Emacs Lisp: Define Function

By Xah Lee. Date: . Last updated: .

Basic function definition is of the form:

(defun function_name (param1 param2 etc) doc_string_optional body)

(defun ff ()
  "print yay"
  (message "Yay!"))
(defun gg (x)
  "add two"
  (+ x 2))
(defun ff (x y)
  "add x and y"
  (+ x y))

When a function is called, the last expression in the function's definition body is returned. (there's no “return statement”.)

(info "(elisp) Defining Functions")

Emacs Lisp Function

Lisp Basics


Lisp Basics

Basics

Lisp Data Structure

Function

Lisp Symbol

Lisp Misc

Working with Elisp