c ++ - 模式挂钩和c-mode-hook似乎运行两次 [英] c++-mode-hook and c-mode-hook appears to run twice

查看:222
本文介绍了c ++ - 模式挂钩和c-mode-hook似乎运行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个命令启动emacs

I use this command to start emacs

$ emacs -Q c-mode-test.el

然后我使用C-xC-e来评估每一行

then I use C-xC-e to eval every line

(require 'cc-mode)

(add-hook 'c-mode-common-hook '(lambda () (print "hello")))

(add-hook 'c-mode-hook '(lambda () (print "hello c")))

(c-mode)

此后,minibuffer显示

after this, the minibuffer shows

"hello"

"hello c"

"hello c"
nil

和c ++ - 模式挂钩运行只是一样的

and c++-mode-hook run just the same

(add-hook 'c++-mode-hook '(lambda () (print "hello c++")))

(c++-mode)

minibuffer

the minibuffer

"hello"

"hello c++"

"hello c++"
nil

为什么它运行两次或出现问题。

why it run twice or something wrong.

推荐答案

你使用错误的钩子为您的C文件。使用正确的钩子是c-mode-hook。

You are using the wrong hook for your "C" files. The correct hook to use is "c-mode-hook".

钩子c-mode-common-hook在每种c风格语言之前运行。也就是说,该钩子适用于许多语言,如java,objective-c,awk等。您可以找到有关这些挂钩的更多信息 here

The hook "c-mode-common-hook" is run before every c-style language. That is, the hook is run for many languages such as java, objective-c, awk and others. You can find more information about these hooks here.

这篇关于c ++ - 模式挂钩和c-mode-hook似乎运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆