Table of Contents

Elisp Cheat Sheet

Assignment

(Not) Eval

Control

Simple Lists

Association Lists (Alist)

Alists can be seen as simple lists with special elements (so called cons cells), representing an association between key and val.

Strings

Symbols

Shell

Interactive

Major Modes

;; sample-mode.el -*- coding: utf-8 -*-
;;
;; Sample Mode
;; Copyright (C) 2017 Ralf Hoppe <ralf.hoppe@dfcgen.de>
;;
 
(defvar sample-mode-hook nil)
 
(defconst sample-mode-syntax-table
  (let ((table (make-syntax-table)))
    (modify-syntax-entry ?\" "\"" table) ; string delimiter
 
    (modify-syntax-entry ?/ "<124" table)
    (modify-syntax-entry ?* "<23b" table)
    (modify-syntax-entry ?\n ">b" table) ; \n is comment end for (only) C++ style
    (modify-syntax-entry ?# "<" table)
    table))
 
(defconst sample-font-lock-keywords
  '(("\\(builtin1\\|builtin2\\)\\>" . font-lock-builtin-face)
    ("\\<\\(keyword1\\|keyword2\\)\\>" . font-lock-keyword-face)
    ("\\<\\(type1\\|type2\\)\\>" . font-lock-type-face)
    ("\\<Sample[0-9a-zA-Z_]*\\>" . font-lock-function-name-face)
    ("\\<\\(SAMPLE\\|Sample_\\)[0-9a-zA-Z_]*\\>" . font-lock-constant-face)
    ))
 
(define-derived-mode sample-mode c-mode "Sample" :syntax-table sample-mode-syntax-table
  (set (make-local-variable 'font-lock-defaults) '(sample-font-lock-keywords))
  (set (make-local-variable 'indent-line-function) 'c-indent-line)
  (setq-local comment-start "// ")
  (setq-local comment-end "")
  (font-lock-fontify-buffer)
  (run-hooks 'sample-mode-hook))
 
(add-to-list 'auto-mode-alist '("\\.sample\\'" . sample-mode))
 
(when (featurep 'speedbar)
  (speedbar-add-supported-extension ".sample"))
 
(provide 'sample-mode)
1)
Citation from Emacs help: This declares that neither programs nor users should ever change the value. This constancy is not actually enforced by Emacs Lisp, but the symbol is marked as a special variable so that it is never lexically bound.
2)
For details see the article by Artur Malabarba: Understanding letf and how it replaces flet.
3)
A sequence may be a list, a vector, a bool-vector, or a string.
4)
Strictly avoid using quote for that. For details see the article by Artur Malabarba: Get in the habit of using sharp quote.
5)
For standard symbol properties (plist) see Emacs Lisp Manual.
6)
There is nothing special todo in this case, because current-prefix-arg is retained during interactive command processing.