4

Why is the third line in this code indented "too much" to the left? It feels "off" to me.

enter image description here

(defun hello-world nil
  "Greet the world.
This function implements the canonical example program."
  (interactive)
  (message "Hello world!"))
Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40

1 Answers1

10

It's so the docstring will look normal when the user views it in the help system.

The first line of the docstring is indented. Since the G directly follows the double quote " there is no indentation in first line of the printed version of the string. The newline at the end of the first line of the string is part of the string.
If you would add indentation to the second line of the string. That indentation would also be part of the printed representation of the string. That is most likely unwanted.

Tobias
  • 32,569
  • 1
  • 34
  • 75
Sue D. Nymme
  • 1,406
  • 12
  • 13
  • do you have a screenshot – american-ninja-warrior Jan 25 '19 at 16:19
  • 6
    Evaluate the lisp code by placing your cursor after the last parenthesis and pressing `C-x C-e`. Then check the help with `C-h hello-world` and see for yourself. :) Experiment to see what happens when you modify the docstring. – Lorem Ipsum Jan 25 '19 at 16:44
  • OTOH, the help system could strip off spaces at the beginning of lines when displaying docstrings. This would only be a problem if there are docstrings with intentional indentation. – Barmar Jan 25 '19 at 20:20
  • @Barmar it would also be a problem wrt maximum line lengths in the code. There's simply no benefit to expending effort on anything like that. The current approach is the simplest and most sensible approach (and I've never seen anyone get confused by it before). – phils Jan 25 '19 at 22:05
  • And Lisp mode doesn't really provide any easy way to type a string with all the lines indented like that. – Barmar Jan 25 '19 at 22:06