emacs format

时间:2014-05-08 23:11:40   收藏:0   阅读:395

    格式化源码是很常见的需求,emacs有个indent-region函数用于格式化选定的代码,前提是你处在某个非text mode下,如c-mode或者java-mode之类。如果要格式化整个文件,你需要先选定整个文件(C-x-h),然后调用indent- region(或者 C-M-\ )。两个命令总是麻烦,我们可以定义个函数搞定这一切,并绑定在一个特定键上,实现一键格式化:

;;格式化整个文件函数
(defun indent
-whole ()
  (interactive)
  (indent
-region (point-min) (point-max))
  (message 
"format successfully"))
;;绑定到F7键
(global
-set-key [f7] indent-whole)


    将这段代码添加到你的emacs配置文件(~/.emacs),重启emacs,以后格式化源码都可以用F7一键搞定。

emacs format,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!