分页: 1 / 2

用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-17 16:17
cuiaoxiang
我现在用了最简单的缩进设置:
(add-hook 'c++-mode-hook '(lambda() (c-set-style "stroustrup")))
基本上缩进的非常令人满意,但是没新起一行,光标都会自动跳到行首,然后再一下“跳”到缩进的位置上,
这样来回跳动很不习惯。
Windows 下用过几个 IDE 缩进都不是这个方式的,回车新起一行光标直接跳到要缩进的位置。
不知道应该怎么设置。

另外一个问题是 C++ mode 下似乎不能正确识别变量名称,具体情况看以下截图:
Screenshot-emacs@test.cpp.png

代码: 全选

for (int i = 0; i < n; ++i)
中,只有第一个 i 被标上了颜色,其他地方也是类似的,
只有在紧跟这类型名称后面的变量才有颜色。
我的意思要不它索性所有变量一律不标颜色,象这样不统一的颜色很难看。。。
我用的是 color-theme 是 midnight,根据我的实验,这个颜色问题与什么 color-theme 没有关系。

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-17 20:35
davyzhu
1. I confront with the same problem that Emacs determine how to indent after I type, my solution is ignore the problem :)
2. It's about face for font lock (you can find more in info elisp)
In my Emacs 23.1, neither first i nor other i change face (their have the default black font color)

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-17 23:09
cuiaoxiang
恩~对于第一个问题,我也感觉并不是特别不方便,只是一个习惯问题,可能我先用 Emacs 反到不习惯 VS 了
第二个问题我明天再试试看,现在怀疑是 CTAG 搞出来的问题。

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-18 0:21
sweating
(add-hook 'c++-mode-hook '(lambda() (c-set-style "stroustrup")))
如果这个不加会如何?
我没有加这个,光标没有去行首.......

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-19 11:25
mikeandmore
用C-j自动缩进
或者(define-key c-mode-base-map (kbd "<return>") 'newline-and-indent) in c-mode-base-hook

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-21 19:17
cuiaoxiang
5 楼能写的具体些吗?
我对 elisp 不熟悉。直接把你给的代码放进 .emacs 文件报错
我想要设置的,因为回车习惯了,不想每次回车按 C-j

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-21 21:16
sweating
cuiaoxiang 写了:5 楼能写的具体些吗?
我对 elisp 不熟悉。直接把你给的代码放进 .emacs 文件报错
我想要设置的,因为回车习惯了,不想每次回车按 C-j
试试把句子放在末尾
不过对Lisp不熟悉用emacs并不是一个好选择,个人认为.........

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-22 3:20
cuiaoxiang
" in c-mode-base-hook" 也是命令么?

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-22 11:59
sweating
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-23 0:22
cuiaoxiang
sweating 写了:
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
对啊,所以我想知道写全怎么搞,我都说了现在还不熟悉 elisp,5L 这么指点江山的来一句对我一点帮助也没有啊

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-23 11:50
sweating
cuiaoxiang 写了:
sweating 写了:
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
对啊,所以我想知道写全怎么搞,我都说了现在还不熟悉 elisp,5L 这么指点江山的来一句对我一点帮助也没有啊

代码: 全选

(define-key c-mode-base-map (kbd "<return>") 'newline-and-indent)
;;;;;让我们举杯祝福那些嵌在重重括号里面的精灵罢....... :em09
;;;;上面那句非常重要,有科学研究表明配置文件中出现上面那句能够使得emacs配置起来更加的舒服
不过如果真要学emacs的话,还是考虑看一下SICP为上
否则用起来真不如vim

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-23 13:30
davyzhu
sweating 写了:
cuiaoxiang 写了:
sweating 写了:
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
对啊,所以我想知道写全怎么搞,我都说了现在还不熟悉 elisp,5L 这么指点江山的来一句对我一点帮助也没有啊

代码: 全选

(define-key c-mode-base-map (kbd "<return>") 'newline-and-indent)
;;;;;让我们举杯祝福那些嵌在重重括号里面的精灵罢....... :em09
;;;;上面那句非常重要,有科学研究表明配置文件中出现上面那句能够使得emacs配置起来更加的舒服
不过如果真要学emacs的话,还是考虑看一下SICP为上
否则用起来真不如vim
Read Emacs book and info doc if you want to *use* it. Read SICP if you want to *extend* it (side effect is you will hate elisp and fancy Emacs to be extended by Guile/Scheme).

I recommend "The Little Schemer". TLS is shorter than SICP but show the core design idea of Scheme.

I have written reviews for SICP and TLS.
SICP:http://book.douban.com/review/2322190/
TLS:http://book.douban.com/review/2215327/

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-27 2:51
cuiaoxiang
sweating 写了:
cuiaoxiang 写了:
sweating 写了:
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
对啊,所以我想知道写全怎么搞,我都说了现在还不熟悉 elisp,5L 这么指点江山的来一句对我一点帮助也没有啊

代码: 全选

(define-key c-mode-base-map (kbd "<return>") 'newline-and-indent)
;;;;;让我们举杯祝福那些嵌在重重括号里面的精灵罢....... :em09
;;;;上面那句非常重要,有科学研究表明配置文件中出现上面那句能够使得emacs配置起来更加的舒服
不过如果真要学emacs的话,还是考虑看一下SICP为上
否则用起来真不如vim
你说的当然是对的,我也学过一点 elisp 的语法,不过平时基本没用,就是说没怎么去捣腾 .emacs 文件。

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-27 18:59
davyzhu
The second problem has an explanation from Emacs mailing list.

That's correct fontification; the first i is fontified because it is
being declared, the other appearances being mere use of the variable.

Re: 用 Emacs 写 C++ 代码的几个问题

发表于 : 2010-04-28 0:40
cuiaoxiang
davyzhu 写了:The second problem has an explanation from Emacs mailing list.

That's correct fontification; the first i is fontified because it is
being declared, the other appearances being mere use of the variable.
恩,好的。有个地方看的不舒服的就是为什么 着色不像很多 编辑器那样把 阿拉伯数字也着色呢?还是可以有参数调整出来的?