Redian新闻
>
emacs问题求教----有关C程序格式
avatar
emacs问题求教----有关C程序格式# Unix - 噫吁兮,危乎高哉
M*d
1
在emacs 中, 对于for 或if 后面的行, 格式一般是这样的:
for ( ....)
{
printf(....);
.......
我怎样才能把它变成:
for ( ....)
{
printf(....);
我查了一些书, 书上说只需对c-brace-offset有所设, 一般设为负值, 以抵消
c-continued-statement-offset. 但我已在.emacs 文件中加入了如下几句:
(setq c-continued-statement-offset 4)
(setq c-brace-offset -4)
但似乎无效, 不知各位大侠有何建议
avatar
m*e
2
I prefer
for ( ) {
printf
}

【在 M****d 的大作中提到】
: 在emacs 中, 对于for 或if 后面的行, 格式一般是这样的:
: for ( ....)
: {
: printf(....);
: .......
: 我怎样才能把它变成:
: for ( ....)
: {
: printf(....);
: 我查了一些书, 书上说只需对c-brace-offset有所设, 一般设为负值, 以抵消

avatar
M*d
3

这样写不但专业, 而且省纸.
但程序一大, 我就懒了, 希望括号都出现在左边, 以便于确定察看范围.

【在 m*****e 的大作中提到】
: I prefer
: for ( ) {
: printf
: }

avatar
a*i
4

~~~~~~
not!
There are different indentation style.
All that you guys have mentioned are professional indentation styles.

【在 M****d 的大作中提到】
:
: 这样写不但专业, 而且省纸.
: 但程序一大, 我就懒了, 希望括号都出现在左边, 以便于确定察看范围.

avatar
M*d
5

我不是不知道K&R convention 也是很好的style. 只是想奉承一下, 讨个大家高兴.
希望各位大侠能对我关于emacs的问题指点一二.
感激不尽.

【在 a*****i 的大作中提到】
:
: ~~~~~~
: not!
: There are different indentation style.
: All that you guys have mentioned are professional indentation styles.

avatar
t*n
6
use (c-set-offset 'substatement-open 0)
and (setq c-basic-offset 4) if you want four space indent.

【在 M****d 的大作中提到】
: 在emacs 中, 对于for 或if 后面的行, 格式一般是这样的:
: for ( ....)
: {
: printf(....);
: .......
: 我怎样才能把它变成:
: for ( ....)
: {
: printf(....);
: 我查了一些书, 书上说只需对c-brace-offset有所设, 一般设为负值, 以抵消

avatar
h*a
7
I stick to K&R indention style.
and I added the following in my .emacs.
(add-hook 'c-mode-hook
'(lambda()
(local-set-key [13] 'c-return) ;;; RET with automatic indent
(local-set-key [16] 'indent-all) ;;; Ctrl-p pretty-prints file
(c-set-style "k&r") ;;; Kernihan & Richie's style
(setq c-basic-offset 4) ;;; 4 spaces for indentations
(c-set-offset 'substatement-open 0) ;;; No indent for open bracket
)
)
;;

【在 t***n 的大作中提到】
: use (c-set-offset 'substatement-open 0)
: and (setq c-basic-offset 4) if you want four space indent.

avatar
M*d
8

himalaya果然高. 我现在已经把这段宝贝加入到.emacs 文件中.
但现在的问题是, 我一敲回车, emacs 便说我没定义什么(好象是和回车有关变量)
于是我又不知道该怎么着了.
大侠您能否release您的.emacs文件, 让大家好好学习一下.
不尽感激.

【在 h******a 的大作中提到】
: I stick to K&R indention style.
: and I added the following in my .emacs.
: (add-hook 'c-mode-hook
: '(lambda()
: (local-set-key [13] 'c-return) ;;; RET with automatic indent
: (local-set-key [16] 'indent-all) ;;; Ctrl-p pretty-prints file
: (c-set-style "k&r") ;;; Kernihan & Richie's style
: (setq c-basic-offset 4) ;;; 4 spaces for indentations
: (c-set-offset 'substatement-open 0) ;;; No indent for open bracket
: )

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。