TransWikia.com

Emacs auto-indenting comments in an unhelpful manner

Emacs Asked on November 30, 2021

New Emacs user here. Hitting enter after a semicolon commented line in any file type (.el and .lisp at the very least) indents the comment in a very unhelpful way that I have to assume is not intended behavior. This problem does not occur if I move away from that comment line in any way besides hitting return (triggering auto-indent presumably).

For example, If I type the following

; this is a comment

Then hit return, I get the following (32 spaces indentation)

                                ; this is a comment

What is causing this behavior, and how can I prevent it?

I am running Emacs 26.3.0.20191219 installed through Chocolatey on Windows 10

One Answer

Unable to post this as a comment, but the indentation is likely part of one of the active modes (probably lisp-mode based on your description). You can do M+x describe-modes to see which modes are active.

This answer provides some background on the history of the common lisp commenting style https://stackoverflow.com/a/6365579

This question and answers describe why the single ; indents differently than multiple consecutive ; characters: https://stackoverflow.com/questions/14190488/set-comments-at-the-same-indentation-level-as-all-forms, namely that lisp-indent-line hardcodes it with the following comment

          ;; Single-semicolon comment lines should be indented
          ;; as comment lines, not as code.

Answered by einfeyn496 on November 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP