2

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

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

Instead of this:

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

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:

(add-hook
 'emacs-lisp-mode-hook
 (lambda ()
   ;; stuff goes here!
   ))
3
  • Evaluating that macro will do that as it contains an indentation declaration.
    – wasamasa
    Jul 29 '17 at 18:57
  • I tried evaluating the macro linked and it didnt change indentation behavior.
    – ideasman42
    Jul 29 '17 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 '17 at 19:05
2

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
`lisp-interaction-mode-hook'."
  (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, privacy policy and cookie policy

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