[英]Emacs CEDET Hook
I want to hook CEDET modes to c++ mode. 我想将CEDET模式挂钩到c ++模式。 I am using the following script in my .emacs file: 我在.emacs文件中使用以下脚本:
(add-hook 'c++-mode-hook
(lambda ()
...
(my_cedet_load)
)
)
where 哪里
(defun my_cedet_load ()
(interactive)
(semantic-mode)
(global-semantic-stickyfunc-mode t)
(global-semantic-idle-scheduler-mode t)
(global-semantic-idle-completions-mode t)
(global-semantic-highlight-edits-mode t)
)
Now, the problem is that once I open a .cpp file, the semantic-mode is enabled in all buffers. 现在,问题是,一旦我打开.cpp文件,就会在所有缓冲区中启用语义模式。 How do I only enable such mode in only .cpp files? 我如何仅在.cpp文件中启用此类模式?
Semantic is a global minor mode. 语义是一种全局次要模式。 From semantic.el
来自semantic.el
To enable Semantic, turn on `semantic-mode', a global minor mode (Mx semantic-mode RET, or "Source Code Parsers" from the Tools menu). 要启用Semantic,请启用“语义模式”,全局次模式(Mx语义模式RET或“工具”菜单中的“源代码分析器”)。 To enable it at startup, put (semantic-mode 1) in your init file. 要在启动时启用它,请将(语义模式1)放在init文件中。
As such when you do semantic-mode
it is enabled in all buffers. 因此,当您执行semantic-mode
它将在所有缓冲区中启用。 You can use semantic-inhibit-functions
to restrict the buffers in which semantic
is activated. 您可以使用semantic-inhibit-functions
来限制激活semantic
的缓冲区。 From the documentation 从文档中
List of functions to call with no arguments before Semantic is setup. 在设置Semantic之前调用没有参数的函数列表。 If any of these functions returns non-nil, the current buffer is not setup to use Semantic. 如果这些函数中的任何一个返回非nil,则当前缓冲区不会设置为使用Semantic。
Below is an example of using this variable. 以下是使用此变量的示例。 it would instruct semantic
to be activated only in c-mode
, cc-mode
and java-mode
buffers 它将指示只在c-mode
, cc-mode
和java-mode
缓冲区中激活semantic
(add-to-list 'semantic-inhibit-functions
(lambda () (not (member major-mode '(java-mode c-mode c++-mode)))))
I'm guessing the key lies in the global
word. 我猜测关键在于global
一词。 So use semantic-stickyfunc-mode
instead of global-semantic-stickyfunc-mode
etc. 所以使用semantic-stickyfunc-mode
而不是global-semantic-stickyfunc-mode
等。
Try this: 尝试这个:
(add-hook 'c++-mode-hook 'my-c++-hook)
(defun my-c++-hook ()
(semantic-mode 1)
(semantic-stickyfunc-mode 1)
(semantic-idle-scheduler-mode 1)
(semantic-idle-completions-mode 1)
(semantic-highlight-edits-mode 1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.