1

When typing docstring in python-mode, I always have issue with indentation. If I am at this point (| is the cursor):

def fn():
   """ 
   Args:|"""

If I press Enter, the cursor will move right below the A, and if I press TAB, the cursor will circle between the beginning of the line and right below A, while I want it indented:

def fn():
   """ 
   Args:
       |"""

Currently, I am just pressing SPACE 4-times (I am using 4-spaces indent) after pressing ENTER, but I would like to know if there is a shortcut in emacs to forcefully insert an indentation (4 spaces) regardless of the mode?

I found out that M-RIGHT inserts 4 spaces but when at the beginning of the line, it inserts 4 spaces without moving the cursor, which is pretty annoying.

1
  • 1
    Which indent-rules should apply inside a string? Wherefrom should Emacs that learn? Dec 11, 2019 at 18:58

1 Answer 1

1

C-u space should insert 4 spaces at point.

Beyond this: python-mode.el provides a command py-edit-docstring. This opens the docstring in an own buffer. Which permits to run other text-modes while editing.

python-mode.el is available from Melpa.

3
  • Thanks for the answer. I will try C-u space when I get back to emacs. I'll also try py-edit-docstring but for small docstring I found having to switch buffer pretty annoying.
    – Holt
    Dec 11, 2019 at 19:27
  • py-edit-docstring is thought for larger docstrings with own formatting resp. indent needs. Switching into the edit-buffer is done for you - it needs than C-c C-c to store edits and be back. Dec 11, 2019 at 19:39
  • C-u space works for me, thanks. Unfortunately, I am using elpy and I don't have py-edit-docstring. But anyway, my question was not docstring-specific (this was just an example), so your answer is sufficient for me.
    – Holt
    Dec 12, 2019 at 9:18

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.