4

I have a hard time writing and reading cl-loops with they way they're indented by default as I can't easily tell what the control flow is:

(cl-loop for x below 10
         if (cl-oddp x)
         collect x into odds
         and if (memq x funny-numbers) return (cdr it) end
         else
         collect x into evens
         finally return (vector odds evens))

I'd like it to be indented like how it's shown in its documentation:

(cl-loop for x below 10
         if (cl-oddp x)
           collect x into odds
           and if (memq x funny-numbers) return (cdr it) end
         else
           collect x into evens
         finally return (vector odds evens))

I know this has to do with Indenting Macros manual page. And possibly this question on indenting a common lisp loop in emacs. Additionally, I've looked at a post on irreal and this question on the indentation of lisp forms.

The general idea I got from reading is to use (declare (indent n)) where n is an integer. I see this works for simple examples. However, how I want the cl-loop to be indented seems too complex for this. I need to tell emacs to recognize the specific if else keywords in the cl-loop.

I am confused as I don't see a clear way to properly indent cl-loop. Any ideas?

  • The declaration (debug ...) is for Edebug. – xuchunyang Apr 1 '18 at 12:27
  • Oh, ok. It doesn't have to do with indentation. I'll remove it from my question. – Aquaactress Apr 1 '18 at 12:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.