emacs很强大,但是强大是以复杂的配置为前提的!没有配置好的时候,可能它比notepad还要难用。
前一段时间我就被缩进弄得晕头转向,tab经常是缩进5个空格,源码会乱,等等,我都几乎要放弃emacs了。
今天偶然看了看emacs自带的manual中的cc-mode一节,哇,发现新大陆了!不光讲得很细,还有个例子,拷过来就可以用了,那缩进,怎一个酷字了得!
后来又参考了 王垠、 ann77的主页,将tab和缩进基本搞定,下面是配置内容:
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
(loop for x downfrom 40 to 1 do
(setq tab-stop-list (cons (* x 4) tab-stop-list)))
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
前一段时间我就被缩进弄得晕头转向,tab经常是缩进5个空格,源码会乱,等等,我都几乎要放弃emacs了。
今天偶然看了看emacs自带的manual中的cc-mode一节,哇,发现新大陆了!不光讲得很细,还有个例子,拷过来就可以用了,那缩进,怎一个酷字了得!
后来又参考了 王垠、 ann77的主页,将tab和缩进基本搞定,下面是配置内容:
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
(loop for x downfrom 40 to 1 do
(setq tab-stop-list (cons (* x 4) tab-stop-list)))
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)

在使用emacs过程中,作者遇到了缩进问题,导致源码混乱。通过阅读emacs manual中的cc-mode部分,找到了解决办法,并结合王垠和ann77的配置,成功设置了缩进。配置内容包括设定indent-tabs-mode为nil,default-tab-width和tab-width为4,以及自定义的c-style,确保了在C/C++编程时的缩进风格。通过添加hook函数my-c-mode-common-hook,实现了在进入C模式时自动应用这些设置。
最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



