1

Exploring far-out init files, I found this here:

(defmacro section (name &rest a) `(progn ,@a))
(put 'section 'lisp-indent-function 'defun)

then it's used AFAICT as a sort of wrapper, not sure of the genius behind all this. Thought it would be a good thing to know. Can someone explain what it all means?

1 Answer 1

3

It enables you to write code like this:

(section testing
  (setq a 1)
  (setq b 2))

(section configuration
  (evil-mode)
  (helm-mode))

This code expands to the following:

(progn
 (setq a 1)
 (setq b 2))

(progn
 (evil-mode)
 (helm-mode))

Normal people would write it like this:

;;; testing
(setq a 1)
(setq b 2)

;;; configuration
(evil-mode)
(helm-mode)

All in all, it's a cute trick. You can find out the above by using the macrostep package and seeing the expansion yourself.

2
  • So it adds the idiom of saying "stuff inside this 'section' will be run together because it's all related stuff." Nice. Can't do this so deftly out in Blub-land.
    – 147pm
    Apr 26, 2019 at 17:59
  • Due to progn, the section form also returns the value of the final form which was evaluated.
    – phils
    Apr 27, 2019 at 1:37

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.