After our MS Graph with PowerShell post, we now have a command-line program we can run to run MS Graph queries to retrieve information like contacts and calendar. The next step is to bring this into Emacs, and we're going to cover our basics in this post, and then discuss how to properly run the program asynchronoulsy next time to tie everything together.
An Introduction to Programming in Emacs Lisp is a great gentle introduction to getting productive with elisp.
Here I present a shorter version on how to get going with elisp linking mostly to the reference docs, assuming that you already know a programming language.
C-h f
(provides help for a function), and C-h v
(provides help for a variable). C-h m
to describe the buffer mode, and C-h b
to displays the active key bindings will help you move around.*scratch*
buffer, which uses Lisp Interaction mode, a major mode for typing and evaluating Lisp forms. Simply place the cursor after the code you want to run, and run C-u C-x C-e
to evaluate that expression and insert into the buffer (or C-j
to insert printed text into buffer directly).1
and put the cursor after the closing parens, then run C-j
. You will see the result of the evaluation.(+ 1 2)
to evaluate a function (+
) instead.nil
is the symbol for false
, and for an empty list.t
is the symbol for true
. When bool is expected, any non-nil value will be true.1
or "text"
.(setq a 1)
lets you evaluate a
and yields 1
.(quote a)
or 'a
) yields the un-evaluated expression, which is useful to constant symbols are lists which would otherwise evaluate.(defun my-fun (first-arg &optional second-arg &rest anything-left) "my function" (interactive) (print "hi there"))
.set
or setq
, eg (setq a 123)
.let
, eg (let ((a 1) (b 2)) (print "do something with a and b"))
.(progn (print "hi") "result")
.(if cond then else-forms...)
, (when cond then-forms...)
, (unless cond then-forms...)
.cond
as a kind of switch: (cond (cond-1 result-1) (cond-2 result-2))
.(not cond
), (and cond-forms...)
, (or cond-forms...)
, (xor cond-1 cond-2)
.(while cond then...)
(always nil
rather than last), and the dolist and dotimes macros.This will more than cover everything that we need to integrate MS Graph into Emacs.
Based on the previous section, you should be able to following along and get things working with your own programs. Let's cover some practices on how to organize code then.
.el
files in the library path. It may be handy to call (add-to-list 'load-path "/path/to/my/lisp/library")
if you have many personal libraries. You can require
or autoload
from your .emacs
file. See Libraries of Lisp Code for Emacs for more information.Here are some of the most important reference points when working with the editor.
Happy Emacs Lisp coding!
Tags: emacs