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

Vim、Emacs配置和使用
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#1

帖子 cuiaoxiang » 2010-04-17 16:17

我现在用了最简单的缩进设置:
(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 没有关系。
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
davyzhu
帖子: 109
注册时间: 2009-12-06 21:23

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

#2

帖子 davyzhu » 2010-04-17 20:35

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)
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#3

帖子 cuiaoxiang » 2010-04-17 23:09

恩~对于第一个问题,我也感觉并不是特别不方便,只是一个习惯问题,可能我先用 Emacs 反到不习惯 VS 了
第二个问题我明天再试试看,现在怀疑是 CTAG 搞出来的问题。
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
头像
sweating
帖子: 200
注册时间: 2009-02-07 18:01

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

#4

帖子 sweating » 2010-04-18 0:21

(add-hook 'c++-mode-hook '(lambda() (c-set-style "stroustrup")))
如果这个不加会如何?
我没有加这个,光标没有去行首.......
头像
mikeandmore
帖子: 109
注册时间: 2005-10-13 18:29

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

#5

帖子 mikeandmore » 2010-04-19 11:25

用C-j自动缩进
或者(define-key c-mode-base-map (kbd "<return>") 'newline-and-indent) in c-mode-base-hook
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#6

帖子 cuiaoxiang » 2010-04-21 19:17

5 楼能写的具体些吗?
我对 elisp 不熟悉。直接把你给的代码放进 .emacs 文件报错
我想要设置的,因为回车习惯了,不想每次回车按 C-j
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
头像
sweating
帖子: 200
注册时间: 2009-02-07 18:01

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

#7

帖子 sweating » 2010-04-21 21:16

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

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

#8

帖子 cuiaoxiang » 2010-04-22 3:20

" in c-mode-base-hook" 也是命令么?
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
头像
sweating
帖子: 200
注册时间: 2009-02-07 18:01

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

#9

帖子 sweating » 2010-04-22 11:59

cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#10

帖子 cuiaoxiang » 2010-04-23 0:22

sweating 写了:
cuiaoxiang 写了:" in c-mode-base-hook" 也是命令么?
定然不是XD :em06
对啊,所以我想知道写全怎么搞,我都说了现在还不熟悉 elisp,5L 这么指点江山的来一句对我一点帮助也没有啊
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
头像
sweating
帖子: 200
注册时间: 2009-02-07 18:01

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

#11

帖子 sweating » 2010-04-23 11:50

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
davyzhu
帖子: 109
注册时间: 2009-12-06 21:23

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

#12

帖子 davyzhu » 2010-04-23 13:30

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/
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#13

帖子 cuiaoxiang » 2010-04-27 2:51

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 文件。
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
davyzhu
帖子: 109
注册时间: 2009-12-06 21:23

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

#14

帖子 davyzhu » 2010-04-27 18:59

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.
cuiaoxiang
帖子: 62
注册时间: 2010-02-01 19:08

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

#15

帖子 cuiaoxiang » 2010-04-28 0:40

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.
恩,好的。有个地方看的不舒服的就是为什么 着色不像很多 编辑器那样把 阿拉伯数字也着色呢?还是可以有参数调整出来的?
God grant me the serenity to accept the things I cannot change
the courage to change the things I can
the wisdom know the difference
回复