This blog post shows that its possible to indent like this:

(lispy-dotimes arg
  (when (= (point) (point-max))
    (error "Reached end of buffer"))

Instead of this:

(lispy-dotimes arg
               (when (= (point) (point-max))
                 (error "Reached end of buffer"))

The post has some snippets but not a enough for a beginner to change their emacs configuration.

How would a typical emacs mode hook be modified to indent like this? eg:

 (lambda ()
   ;; stuff goes here!
  • Evaluating that macro will do that as it contains an indentation declaration.
    – wasamasa
    Jul 29, 2017 at 18:57
  • I tried evaluating the macro linked and it didnt change indentation behavior.
    – ideasman42
    Jul 29, 2017 at 19:01
  • The blog post only shows the definition of lispy-save-excursion, evaluating that will only change indentation of calls to lispy-save-excursion. If you want to fix the indentation of lispy-dotimes, you'll have to actually retrieve its source, eval its definition and reindent the example.
    – wasamasa
    Jul 29, 2017 at 19:05

1 Answer 1


You can control such indentation using options lisp-indent-offset and lisp-body-indent, option lisp-indent-function, or symbol property lisp-indent-function. One possible value for option lisp-indent-function is the value of common-lisp-indent-function.

See the Emacs manual, node Lisp Indent (and its parent node, Program Indent), for more information.

See also standard library cl-indent.el.

For example:

(defun lisp-indentation-hack ()
  "Your Lisp indenting.  Use in Lisp mode hooks
such as `lisp-mode-hook', `emacs-lisp-mode-hook', and
  (unless (load-history-filename-element (load-history-regexp "cl-indent"))
    (load "cl-indent" nil t))
  (set (make-local-variable 'lisp-indent-function) 'common-lisp-indent-function)
  (setq lisp-indent-maximum-backtracking  10)
  (put 'define-derived-mode 'common-lisp-indent-function '(4 4 4 2 &body))
  (put 'if 'common-lisp-indent-function '(nil nil &body))
  (when (featurep 'cl-indent)
    (put 'cl-flet 'common-lisp-indent-function
         (get 'flet 'common-lisp-indent-function))
    (put 'cl-labels 'common-lisp-indent-function
         (get 'labels 'common-lisp-indent-function))))

(add-hook 'emacs-lisp-mode-hook 'lisp-indentation-hack)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.