How do I make Emacs auto-indent my C code?

后端 未结 7 1100
一向
一向 2021-01-31 18:53

I\'m just starting to get a feel for emacs, but I am frustrated with it\'s tendency to not indent when I press the return key. I know if I press C-j it will do it, but I can\'t

7条回答
  •  梦谈多话
    2021-01-31 19:22

    Have a look at emacswiki - autoindent

    As suggested there, put following code in your .emacs

    (defun set-newline-and-indent ()
      (local-set-key (kbd "RET") 'newline-and-indent))
    (add-hook 'c-mode-hook 'set-newline-and-indent)
    

    You can customize the variable C Default Styl. In your emacs go to Options->Customize Emacs->Specific Option, then type c-default-style and set to your choice. By doing this, you don't need to hit TAB. Type from start of the line and as you hit ";" , it will be automatically indented.

    Hope this helps

提交回复
热议问题