简体   繁体   English

打开文件时,是否可以将.emacs文件设置为自动缩进源文件?

[英]Can I setup my .emacs file to auto-indent my source file when I open the file?

I want to be able to open a .java or .c file and have it automatically indent every line to the correct spacing. 我希望能够打开.java或.c文件,并自动将每行缩进到正确的间距。 What line(s) can I add to my .emacs file to accomplish this? 我可以在.emacs文件中添加哪些行来完成此操作?

I certainly wouldn't want to do that — it's a little bit too automated for my taste. 我当然不想这么做,因为我的口味有点太自动化了。 But if you're really sure, the following should do the trick: 但是,如果您真的确定,可以使用以下方法:

(defun jdn-indent-buffer ()
  (interactive)
  (indent-region (point-min) (point-max)))

(add-hook 'c-mode-hook #'jdn-indent-buffer)
(add-hook 'java-mode-hook #'jdn-indent-buffer)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM