0

I have this code snippet in my init file:

'(mode-line-inactive
  ((t
    (:weight light
             :box (:line-width -1 :color "blue")
             :foreground "red"
             :background "green"
             :inherit mode-line))))

Is that the proper way to indent the code?

I would think it would be easier to read if it were like so:

'(mode-line-inactive
   ((t
     (:weight light
      :box (:line-width -1 :color "blue")
      :foreground "red"
      :background "green"
      :inherit mode-line))))

But the former is what it defaults to in emacs.

Or should I be formatting the code differently?

  • 1
    There is no "proper" way to indent Lisp code. There are various ways, some more conventional (common) than others. Use whatever way you like. And you can adjust the automatic indentation to get what you want. The indentation you see here is the default indentation for a literal list. Without teaching it what you think and want, Lisp does not know (or care) that you want to think of this particular literal list as being a list of two-element lists, the second of which is a plist - and so on. – Drew Aug 9 '18 at 4:15
  • 1
    If your question is whether you should format this code differently the answer is do whatever you and your code readers like. If your question is what formatting do others like (opening a style discussion), that's primarily opinion-based, so maybe not a good question for SE. If the latter, maybe try something like Reddit instead. – Drew Aug 9 '18 at 4:18
  • 1
    Actually, I'd say that here #2 is the correct one, and #1 is simply the artifact of how Emacs (mis)understands the Lisp code. Essentially, Emacs "thinks" here that it is indenting a function call, thus it tries to align all arguments to the function. But... it's not a function, and it's where the editor comes as confusing to the programmer. I don't know a way to fix this, but if you don't mind doing it manually, that's still a better option than letting Emacs decide this for you. – wvxvw Aug 9 '18 at 9:04
  • 1
    A great way to play with the way you format is with aggressive-indent-mode (github.com/Malabarba/aggressive-indent-mode). Copy your code on the scratch buffer, activate the mode, and have fun moving the parenthesis around and having the indentation automatically follow. – Guilherme Salomé Aug 10 '18 at 0:53

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.