Category Archives: emacs

On this page:

Read Lisp, Tweak Emacs [Beginner 1/4]: How to try Emacs Lisp

This entry is part 1 of 4 in the series Read Lisp, Tweak Emacs

Okay! People have given lots of great feedback on the e-mail course. It’s time to post the course content on my blog so that you can read it here too (or search for it in case you want). =) I’ll post these one section at a time, but you can read the current draft at http://emacslife.com/how-to-read-emacs-lisp.html if you want to. Any updates will probably be over there too!

Some conventions we’ll use:

  • Inline code will be boxed and monospace in the HTML version and generally surrounded by equal signs in plain text.
  • Code samples will be monospace and in boxes in the HTML version, and enclosed in #+begin_src#+end_src in plain text. Example:
    (message "Hello world")
    

After this section, you should be able to

  • find Emacs Lisp code to study and use
  • try Emacs Lisp code before saving it to your configuration (that way, you don’t have to keep restarting Emacs)
  • add code to your configuration so that it runs whenever Emacs starts

Finding Emacs Lisp code

It’s easier to learn how to read Emacs Lisp when you start with simple examples that will help you use Emacs more effectively. Here are some useful sources:

Emacs documentation

Manuals and FAQs for Emacs-related tools often include code snippets. For example, the Emacs FAQ has an entry like this:

5.47 How can I tell Emacs to fill paragraphs with a single space after each period?
===================================================================================

Add the following line to your `.emacs' file:

     (setq sentence-end-double-space nil)

You can read the Emacs manual by typing C-h i (info) and choosing the Emacs item. If you’re on a terminal that doesn’t understand the C-h key, use F1 or M-x help whenever you see a reference to C-h, or use M-x to call the command by name (ex: F1 i, or M-x info). To jump directly to the Emacs manual, you can use C-h r (info-emacs-manual). You can also find the Emacs Manual at http://www.gnu.org/software/emacs/manual/emacs.html .

Packages

Emacs has lots of packages in different repositories, many of which require a little extra code in order to be used to full effect. You can use M-x package-list-packages to list the packages that Emacs knows about by default. You will need an Internet connection for that.

If you’re new to Emacs, try getting used to Emacs without packages first. There’s plenty of functionality already built in. When you come across a gap, chances are that someone has written a package to make Emacs behave the way you want it to. Since there are lots of packages that do similar things, you might want to look for recommendations or ask people which ones you should start with.

In addition to the default package repository, there are other community-supported repositories. See Installing packages if you would like to install a package from a different repository.

If you install a package, check out the README, description, documentation, or source code comments for interesting packages to find suggested code to add to your Emacs configuration.

Here are some packages that might be interesting:

  • company: adds text completion
  • yasnippet: snippets and templates
  • undo-tree: visualize your undo/redo history

You will need to be connected to the Internet in order to view and install packages. You can use M-x package-list-packages to show the available packages and read the descriptions for the packages above.

Webpages, blog posts, and the Emacs Wiki

While searching for information related to Emacs, you’ll probably come across lots of Emacs Lisp snippets. The EmacsWiki has lots of code, too. Since this is a community-maintained wiki, you may come across code that is out of date or that refers to packages that you don’t have. I’ve included common errors in this guide to help you figure things out – see “Oh no! I have an error!”

Here are some sites you may want to check out:

Mailing lists, newsgroups, and Q&A sites

There are many places where you can ask for help with Emacs. gnu.emacs.help is available as a mailing list or as a newsgroup – check your favourite Usenet server or use Gmane. StackOverflow and Quora are popular as well. If you ask questions there, you might get answers in the form of Emacs Lisp code. You’ll also come across Emacs Lisp code while searching for answers.

Find a snippet of Emacs Lisp code you want to understand more deeply, or look at the examples in the sections below.

Trying out code

It’s easier to understand code if you can experiment with it. Emacs Lisp code is made up of symbolic expressions (known as S-expressions, expressions, or sexp for short). Expressions are usually enclosed in pairs of parentheses. There are several ways you can try Emacs Lisp expressions before saving them in your configuration.

Note: As you experiment with Emacs Lisp, you might run into errors. Check out “Oh no! I have an error!” for some common errors and what to do about them.

Here are some ways you can run Emacs Lisp code. I’ll explain them in more detail below.

  • M-x ielm (Inferior Emacs Lisp Mode) – evaluates expressions after you press RET, which is handy for pasting in code
  • The *scratch* buffer and Emacs Lisp files – makes it easy to edit and re-evaluate expressions
  • M-: (eval-expression) – good for quickly evaluating Emacs Lisp code while you’re doing something else
  • C-x C-e (eval-last-sexp) – handy when reading expressions in manuals or other text

M-x ielm (Inferior Emacs Lisp Mode)

The Inferior Emacs Lisp Mode gives you a prompt where you can type or paste in Emacs Lisp code. Start it with M-x ielm. Press RET after you enter code, and the results will be displayed. “Inferior” is a technical term referring to how it’s run, not a comment on the simplicity of the tool or the code you want to try. You can go to previously-executed code, change things, and press RET to run (or “evaluate”) it again.

If you’re copying or typing code, make sure your parentheses are all matched – every “(” should have a “)“. IELM won’t run the code unless it sees the closing parenthesis. So the following code is incomplete:

(message "Hello

but this will work:

(message "Hello world")

You can use M-p (comint-previous-input) to go through the previously-typed expressions. M-n (comint-next-input) goes forward.

Tip: When you’re trying out an unfamiliar mode, use C-h m (describe-mode) to learn more about the commands that are available in that mode.

The *scratch* buffer and Emacs Lisp .el files

When Emacs starts, it creates a buffer called *scratch* with the following contents:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

You can add code to the end.

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

(message "Hello world")

Note: ; is the comment character. Anything after the comment character is considered part of the comment. Make sure you add your code on a new line, not in the comment. ;; above is how we usually start comments that take up the entire line.

To run code (“evaluate” it, in Emacs terms), you can use the following commands based on what you want to run:

  • M-x eval-buffer runs all the code in the current file or buffer.
  • M-x eval-region runs the code in the selected region. You can select a region of text by using the mouse. Alternatively, you can type C-SPC to mark the start of the region, then move your cursor to the end of the region. If you want to learn more about selecting regions, check out the Emacs tutorial (C-h t, C-h t, or M-x help-with-tutorial).
  • C-x C-e (eval-last-sexp) runs the expression (S-expression, or sexp) before the cursor. NOTE: Your cursor should be after the closing parenthesis, not on it.

In the *scratch* buffer, you can also press C-j (eval-print-last-sexp) after an expression in order to evaluate it and display the results in the buffer.

The *scratch* buffer is not automatically saved. If you would like to save your code for future use, you can create a file with an .el ending. el stands for Emacs Lisp, and Emacs will open these files in Emacs Lisp mode. The commands listed above work in Emacs Lisp files.

M-: (eval-expression)

If you want to quickly try a single expression, you can use M-: (eval-expression). It will display the results in the echo area near the bottom of your screen. If you want to insert the results into your buffer, call it with C-u M-: instead. For example, you can use C-u M-: (* 18 2) to multiply 18 and 2 quickly. To review previous results, you can switch to the *Messages* buffer.

C-x C-e (eval-last-sexp)

C-x C-e (eval-last-sexp) runs the expression (S-expression, or sexp) before the cursor. NOTE: Your cursor should be after the closing parenthesis, not on it. C-x C-e (eval-last-sexp) works in lots of buffers, not just in Emacs Lisp ones. You can use it to quickly try expressions while reading manual pages or other documentation.

You can get the text file for this lesson from http://emacslife.com/read-lisp-tweak-emacs/beginner-1-try-emacs-lisp.txt . If you’re reading this lesson in Emacs, try putting your cursor after the closing ) and calling C-x C-e (eval-last-sexp) on the following line:

(menu-bar-mode -1)

This turns off the menu bar along the top of your Emacs window. If you like the menu bar, you can turn it on again by evaluating:

(menu-bar-mode 1)

As with M-: (eval-expression), you can use the C-u prefix to insert the results instead of displaying them. For example, try using C-u C-x C-e (eval-last-sexp) to evaluate the following expression:

(* 6 7)

If you want that code to run every time you start Emacs…

then add it to your ~/.emacs.d/init.el file. You can generally add new code at the end. If the code has something to do with add-to-list and load-path, it might be good to add it to the beginning instead.

Note: The Emacs configuration file used to be ~/.emacs, and most webpages refer to that. ~/.emacs still works – in fact, if you have that, it may stop Emacs from loading ~/.emacs.d/init.el. On the other hand, if you use ~/.emacs.d/init.el (and move your ~/.emacs code to that file instead), then you have one less hidden file in your home directory (~). If you’re adding code to your config and it’s not getting loaded, make sure you have either ~/.emacs or ~/.emacs.d/init.el, but not both.

When you’re starting out, it’s a good idea to keep your configuration in one file. Later on, you can split it up into multiple files if you want.

Practice

Try this out:

Next module: “How can I understand what Emacs Lisp code does?”

  1. Browse through http://www.emacswiki.org/emacs/CategoryDotEmacs for some code that looks like it will make Emacs work more like the way you want it to. If you need help figuring it out, send me a copy of the code ([email protected]).
  2. Use M-x ielm to evaluate this expression interactively:
    system-type
    

    This shows you the value of the system-type variable. Note: Variables can be evaluated without the parentheses, but functions can’t. Use You can use ielm to call functions like this, though:

    (max 2 6 10 5)
    
  3. Use M-: (eval-expression) buffer to evaluate the following expression:
    (* 21 2)
    

    M-: is handy for quick calculations. Remember, you can use it with
    C-u (that is, C-u M-:) to insert the result into the buffer.
    Try it now: C-u M-: (* 21 2)

  4. Use C-x C-e (eval-last-sexp) to evaluate the expression below. If you are reading this in Emacs, you can evaluate it by putting your cursor after the last ) and calling C-x C-e (eval-last-sexp). If you are reading this outside Emacs, you can copy that text into any buffer and then use C-x C-e (eval-last-sexp) to evaluate it.
    (* (+ 1 2) 3)
    
  5. Add (message "Hello, world!") to the end of your ~/.emacs.d/init.el (or ~/.emacs, if you’re using that file instead). Use M-x eval-buffer to load your config. It should display the message near the bottom of your screen. If you restart Emacs, you should also see that message briefly.
  6. Call M-x visual-line-mode to tell Emacs to visually wrap lines without actually changing the text. If you like this, add (visual-line-mode) to your ~/.emacs.d/init.el.
Series NavigationRead Lisp Tweak Emacs [Beginner 2/4]: How to understand what Emacs Lisp code does »

Emacs: beginner, intermediate, advanced

In a recent Emacs Chat, Bozhidar Batsov mentioned the need for more intermediate to advanced resources, not just tutorials covering the same introductory ground. It got me thinking about different levels of Emacs use, and what kinds of things would help people move upwards.

I think of Emacs beginners as people who are getting the hang of using Emacs. They might even use Emacs regularly. They might have installed and configured a number of packages with lots of help from StackOverflow, coworkers, IRC, and so on. They are not yet comfortable with customization, so they find workflow descriptions and code snippets helpful.

Intermediate users are those who have figured out workflows that fit them well. They may have installed and configured a number of packages. They’re comfortable reading the documentation to figure out how to customize variables, and may even have written a few custom functions and keybindings. They’ve dived into the Emacs Lisp Reference Manual a few times, and know where to go to find examples and common idioms. Some have written tutorials to help beginners get started with useful packages or tips.

Advanced users are those who can imagine a new use for Emacs and make it happen. Here’s where you’ll find people with complex workflows built around combinations of packages, people who write custom modes and other tools, and people for whom hacking Emacs has become a recreational activity. They’re comfortable digging through the source and creating their own versions. They might even package the new code in order to share those features with others. Their code feels like Emacs code, following conventions and idioms.

What have I learned from Emacs Chats about how people move from one stage to the other?

Beginner to intermediate: “Oh, neat, Emacs can do that! I wonder how I can…”

Many people find it inspiring to see how other people have tweaked Emacs. Demos, examples, IRC conversations, and peeking over people’s shoulders are all great ways to find out that Emacs can do more than you think it does, which is an important motivator for moving from the beginner stage to the intermediate stage.

Useful resources could include:

  • Demos of interesting features that require some configuration, with notes on other things you might tweak along the way (exercises for the reader?)
  • Walkthroughs of advanced users’ workflows, since people pick up little tips that advanced users may forget to mention
  • Tips on how to read and modify code

Intermediate to advanced: “I’m in Emacs all the time anyway, so I might as well…”

Going from intermediate to advanced tends to involve a lot of practice in creating little tools, much rereading of the Emacs Lisp Reference and well-written package source code, and participation in the community (through mailing lists, IRC, StackOverflow, Github, etc). It can involve a commitment to use Emacs for way more than you might expect, possibly pushing it to be equivalent or superior to other tools.

People who maintain packages with active communities or who answer questions on mailing lists/newsgroups StackOverflow/Quora/IRC tend to grow a lot, too, since they actively learn from other people’s questions.

Useful resources could include:

  • Practical applications of concepts from the Emacs Lisp Reference
  • Tweaks using internal or obscure code
  • Posts that new features or “What if…” and walk through the code (and possibly the thought process as well)

Emacs is so big, so people probably have different levels of competence for different things. For example, one can be a beginner at Smartparens (memorized the keybindings for some common operations), while being an intermediate/advanced user of completions (have defined a custom completion backend).

What kinds of resources have helped you move from stage to stage? What would you like to see more of?

Emacs Chat: Oh no, my chat with Bodil Stokke didn’t get recorded!

Camtasia said it was recording the whole thing, and then when I went to edit it, I found that I only had the first 9 minutes. Extracting the .camrec didn’t get me any additional data. Nooooooooooooooooooooooooo! That’s what I get for doing an interview without two recording systems. Normally I use Google Hangout On Air’s built-in recording and Camtasia Studio as a backup, but since I was using appear.in, I only had Camtasia Studio running.

And it was a cool demo/discussion of Flycheck with Haskell (including better ways to do things), Tern, js2-mode, smartparens, tagedit, the XWidgets branch and running Reveal.js presentations inside Emacs, styling tips (Powerline, Nyancat, font-locking), the Emacs Lisp Reference…

We might be able to reschedule after I crawl out from under a rock and also hammer a solid backup screen recording strategy in place, although Bodil mentioned she’s open to using Google Hangout on Air even though it uses some proprietary plugins.

In the meantime:

http://twitter.com/bodil

https://gitlab.com/bodil/emacs-d/tree/master

Argh. Bodil, I’m so sorry!

Emacs Chat: Christopher Wellons

Christopher Wellons (nullprogram.com, github.com/skeeto/) started using Emacs nine years ago and has built all sorts of nifty customizations since, including something that plays Tetris for you. He demonstrates the benefits of having an HTTP server running inside Emacs by using Skewer to interact with a web browser and Impatient-mode to share his syntax-highlighted buffer through the Web. In addition, he covers foreign function interfaces, packages, and other good things. Check it out!

Links: 

Download the MP3

Playing around with Clojure, Cider, and 4Clojure

4Clojure has a lovely series of exercises to help you practice Clojure. I don’t know much Clojure yet. I’ve basically been taking what I know of Emacs Lisp and trying to cram it into Clojure syntax. (compose is pretty cool!) I should probably read through a Clojure tutorial and some kind of syntax reference. (Hyperpolyglot is neat!) But hey, I’ve gotten through 21 problems so far.

Tom Marble and I were chatting about Clojure, Emacs, and Org Babel. As it turns out, there are lots of ways to interact with 4clojure problems from within Emacs. Tom told me about the 4clojure package by Joshua Hoff, which is probably slightly improved with the following code:

(require 'clojure-mode)
(defun my/4clojure-check-and-proceed ()
  "Check the answer and show the next question if it worked."
  (interactive)
  (let ((result (4clojure-check-answers)))
    (unless (string-match "failed." result)
       (4clojure-next-question))))
(define-key clojure-mode-map (kbd "C-c C-c") 'my/4clojure-check-and-proceed)

That one doesn’t track your progress on the website, though, so you’ll still want to copy and paste the solution yourself.

I like working within Org Mode so that I can easily take notes along the way. Here are the notes I took while figuring out how to get Clojure and Org to work together. http://www.braveclojure.com/basic-emacs/ is nice. http://bzg.fr/emacs-org-babel-overtone-intro.html has a good introduction. Here’s what I used from those:

Install Java (at least version 6), Clojure and Leiningen.

Install the clojure-mode and cider Emacs packages

Evaluate this by moving the point to the #+begin_src line and running C-c C-c

(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-refresh-contents)
(package-install 'clojure-mode)
(package-install 'cider)

And then evaluate this afterwards:

(add-to-list 'org-babel-load-languages '(emacs-lisp . t))
(add-to-list 'org-babel-load-languages '(clojure . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)
(setq nrepl-hide-special-buffers t
      cider-repl-pop-to-buffer-on-connect nil
      cider-popup-stacktraces nil
      cider-repl-popup-stacktraces t)
(cider-jack-in)

That should let you evaluate this:

(list? '(1 2 3 4))

—————–
And that let me do stuff like this for #27: Palindrome Detector:

(defn __ [x] (= (seq x) (reverse x)))
(list
  (false? (__ '(1 2 3 4 5)))
  (true? (__ "racecar"))
  (true? (__ [:foo :bar :foo]))
  (true? (__ '(1 1 3 3 1 1)))
  (false? (__ '(:a :b :c))))
true true true true true

If all the results are true, then I’ve passed. Yay! In the web interface, __ is where your answers go. Fortunately, it’s also a valid Lisp name, so I can defn a function to replace it when testing locally. The proper answer would probably be something like (fn [x] (= (seq x) (reverse x))) when submitted through the web interface, which is close enough.

it would be great to have something like 4clojure for Emacs Lisp – a site where you can practise solving small, well-defined problems. =) Has someone already written one?

Cobbling together a semi-auto-responder using Emacs, Gnus, and org-contacts

It turns out that lots of people are interested in an e-mail-based course for learning Emacs Lisp. Yay! =) Maybe it’s the idea of bite-size chunks. Maybe it’s the ease of asking questions. Maybe it’s the regular reminders to work on something. Who knows? Whatever the reason, it’s awesome to see so many people willing to join me on this experiment.

Since this is my first time to venture into the world of teaching people online, I wanted to see how far I could push actually doing all the mails myself, instead of just signing up for an Aweber account and handing everyone off to an impersonal autoresponder. I dusted off Gnus, offlineimap, and org-contacts, and started figuring out my workflow. I’ll share how that workflow’s evolving so that you can get a sense of how someone might write little bits of Emacs Lisp to make something repetitive easier.

For the first little while, I got by with using C-x r s (copy-to-register) and C-x r i (insert-register) to store the text that I needed.
Sometimes I needed to paste in the welcome message and checklist, and sometimes I needed to paste in the first lesson. By using registers, I could insert whatever I wanted instead of going through the kill ring. I also had another bit of templated code in yet another register so that I could easily create an org-contacts entry for the person whose mail I was replying to. In the beginning, I used tasks under each person’s heading to indicate that I had sent them the checklist or that I had sent them the first lesson. Eventually, I changed my org-contacts notes so that the TODO state of each person showed which lesson I was going to send them next, or CHECKLIST if I was waiting for their reply to the checklist. I also set up Org so that it would automatically log when the TODO state was changed.

#+TODO: TODO | DONE
#+TODO: CHECKLIST(c!) BEGINNER1(1!) BEGINNER2(2!) BEGINNER3(3!) BEGINNER4(4!) FULL(f!) | FINISHED(x!)
#+TODO: | CANCELLED

* Who
** CHECKLIST Jane Smith ...
** BEGINNER1 John Smith
   SCHEDULED: <2014-05-28 Wed>
   :PROPERTIES:
   :EMAIL: [email protected]
   :END:
(notes from the messages, etc.)

I wrote some code to make it easier to send someone a checklist and create a note for them in my org-contacts file. I bound it to C-c e c for convenience.
(The bind-key function is defined by a package.)

(setq sacha/elisp-course-checklist-body "... really long text here...")
(defun sacha/elisp-course-checklist ()
  "Copy this message and put it at the end as a checklist item. 
Start a message with the checklist."
  (interactive)
  (gnus-summary-scroll-up 1)
  (with-current-buffer gnus-article-buffer
    (let ((message (buffer-substring-no-properties (point-min) (point-max)))
          (email (cadr (org-contacts-gnus-get-name-email))))
      (with-current-buffer "elisp-course.org"
        (save-excursion
          (goto-char (point-max))
          (save-excursion
            (insert "\n** " message)
            (org-set-property "EMAIL" email)
            (org-todo "CHECKLIST"))))))
  (gnus-summary-followup-with-original nil)
  (goto-char (point-max))
  (insert sacha/elisp-course-checklist-body))
(bind-key "C-c e c" 'sacha/elisp-course-checklist)

This made it easier for me to read the starred messages from my inbox and use C-c e c to get a head start on processing people’s introductory messages.
Yay! I used the register trick to help me reply to people who were ready for the first lesson. After the first few replies, I noticed that the attachment code was fine even if I put that in the register too, so I added it as well.

Things got more complicated when I started processing lesson 2. I didn’t want to have to set up and remember lots of different registers, and I didn’t want to manually update the TODO states either. So I started defining functions that I could call with keyboard shortcuts:

(defun sacha/elisp-course-1 ()
  (interactive)
  (let ((marker (org-contacts-gnus-article-from-get-marker)))
    (if marker
        (org-with-point-at marker
          (org-todo "BEGINNER2"))))
  ;; Find the person's contact record
  (gnus-summary-scroll-up 1)
  (gnus-summary-followup-with-original nil)
  (message-goto-subject)
  (message-delete-line)
  (insert (concat "Subject: " sacha/elisp-course-1-subject "\n"))
  (goto-char (point-max))
  (insert sacha/elisp-course-1-body))
(bind-key "C-c e 1" 'sacha/elisp-course-1)
(defun sacha/elisp-course-2 ()
  (interactive)
  (let ((marker (org-contacts-gnus-article-from-get-marker)))
    (if marker
        (org-with-point-at marker
          (org-todo "BEGINNER3"))))
  ;; Find the person's contact record
  (gnus-summary-scroll-up)
  (gnus-summary-followup-with-original nil)
  (goto-char (point-max))
  (insert sacha/elisp-course-2-body))
(bind-key "C-c e 2" 'sacha/elisp-course-2)

Really, though, it doesn’t make sense to have a lot of duplicated code. So I wrote some code that would use the person’s TODO keyword to look up the message to send them, and then move them to the next keyword. Now I don’t need sacha/elisp-course-1 or sacha/elisp-course-2 any more.

(setq sacha/elisp-course-info
      `(("CHECKLIST" nil ,sacha/elisp-course-checklist-body)
        ("BEGINNER1" ,sacha/elisp-course-1-subject ,sacha/elisp-course-1-body)
        ("BEGINNER2" ,sacha/elisp-course-2-subject ,sacha/elisp-course-2-body)))

(defun sacha/elisp-course-process (subject body &optional state)
  "Process this course entry."
  (if (derived-mode-p 'org-mode)
      (progn
        ;; Move this node to the next state and compose a message
        (if state (org-todo state))
        (org-todo 'right)
        (message-mail (org-entry-get (point) "EMAIL") subject)
        (goto-char (point-max))
        (insert body))
    ;; Doing this from Gnus; find the person's info
    (let ((marker (org-contacts-gnus-article-from-get-marker)))
      (if marker (org-with-point-at marker
                   (if state (org-todo state))
                   (org-todo 'right)))
      ;; Compose a reply
      (gnus-summary-scroll-up 1)
      (gnus-summary-followup-with-original nil)
      (message-goto-subject)
      (message-delete-line)
      (insert (concat "Subject: " subject "\n"))
      (goto-char (point-max))
      (insert body))))

(defun sacha/elisp-course-guess-and-process (&optional state)
  (interactive (list (if current-prefix-arg (read-string "State: "))))
  (let ((current-state
         (or state (elt
                    (if (derived-mode-p 'org-mode)
                        (org-heading-components) 
                      (let ((marker (org-contacts-gnus-article-from-get-marker)))
                        (if marker (org-with-point-at marker (org-heading-components)))))
                    2))))
    (sacha/elisp-course-process
     (elt (assoc current-state sacha/elisp-course-info) 1)
     (elt (assoc current-state sacha/elisp-course-info) 2)
     state)))
(bind-key "C-c e e" 'sacha/elisp-course-guess-and-process)

Come to think of it, I should totally have it schedule the next update for the next Wednesday, too. ;) That’s just (org-schedule "+wed"). Neat, huh?
And I’m sure there are all sorts of ways the code can be simpler, but it works for me at the moment, so hooray!

I really like this approach. It lets me pull in standard information while also letting me customize the messages and how it fits into my task tracking. I can’t get that with Gmail (even with canned responses), and I’m not sure any CRM is going to be quite as awesome as this. I can’t wait to see how else we’ll tweak this as we go through more conversations. I’d like to get better at:

  • having a consistent place where I can process all the messages and make sure nothing falls through the cracks; I currently star messages to make sure I process them, since the Gmail label folder in IMAP seems to be missing some messages
  • seeing all Gnus conversations related to an org-contacts entry
  • reaching out to people proactively with the next lesson, even if they haven’t e-mailed me (or maybe I should wait for them?)

Anyway, that’s an example of writing a little bit of Emacs Lisp in order to connect different packages. Gnus handles mail, Org handles notes, org-contacts links the two together, and with a little bit of custom code, I can make the combination fit what I want to do. I read the source code of org-contacts to find out how I could look up the appropriate note, and I looked at org-shiftright to find out how to move things to the next TODO state. If you know something that works roughly like what you want it to work, you can find out how it does things and then copy that.

As for the course itself: I’ve been sending people links to the HTML output, attached .txt files (with -*- mode: org -*-) so they can open it in Emacs if they want, and inline text so that they can skim it briefly in their e-mail client if they want to. I’m not perfectly happy with the plain-text formats, but it seems to be a reasonable compromise, and so far people have been able to deal with it. I’ve been improving pieces of it based on feedback on clarity, suggestions for good examples, and so on. I didn’t take all the feedback; after thinking about some of the suggestions, I still preferred it my way. It’s shaping up quite nicely, though!

If you’re curious about the beginner’s course on reading Emacs Lisp, e-mail me at [email protected] and we’ll see how this works out. I’m certainly learning a lot. =)