Skip to content

Instantly share code, notes, and snippets.

@tanyuan
Created March 10, 2016 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanyuan/bb879ecbf8f4ca1e9f7d to your computer and use it in GitHub Desktop.
Save tanyuan/bb879ecbf8f4ca1e9f7d to your computer and use it in GitHub Desktop.
Emacs Lisp basic

Emacs Lisp

Lisp is List Processor. Lisp is a programmable programming language.

Emacs is built by Emacs Lisp, a dialect of Lisp.

something is a variable. Like a pointer point to something defined.

`something is "something" itself.

(+ 2 2) the first element + is evaluated as a function taking into the other two elements.

`(red green blue) is just a list of elements.

; begins a comment line.

Evaluation = Execution

  • C-x C-e: Evaluate with cursor placed at the end of a Lisp list.
  • C-u C-x C-e: Append the evaluation result to the current line.
  • q to quit debugger.

Variables

(set 'carnivores '(lion tiger leopard))

is the same as:

(setq carnivores '(lion tiger leopard))

defun

Define functions.

(defun FUNCTION-NAME (ARGUMENTS…)
  "OPTIONAL-DOCUMENTATION…"
  (interactive ARGUMENT-PASSING-INFO)     ; optional
  BODY…)

let

Local variables.

(let VARLIST BODY…)    

(let ((VARIABLE VALUE)
     (VARIABLE VALUE)
      …)
    BODY…)

if

(if (> 4 5)                               ; if-part
    (message "4 falsely greater than 5!") ; then-part
    (message "4 is not greater than 5!")) ; else-part

Show in the echo area

(message "This will show up in echo area")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment