I want to hook CEDET modes to c++ mode. I am using the following script in my .emacs file:
(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. How do I only enable such mode in only .cpp files?
Semantic is a global minor mode. From semantic.el
To enable Semantic, turn on `semantic-mode', a global minor mode (M-x semantic-mode RET, or "Source Code Parsers" from the Tools menu). To enable it at startup, put (semantic-mode 1) in your init file.
As such when you do semantic-mode
it is enabled in all buffers. You can use semantic-inhibit-functions
to restrict the buffers in which semantic
is activated. From the documentation
List of functions to call with no arguments before Semantic is setup. If any of these functions returns non-nil, the current buffer is not setup to use 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
(add-to-list 'semantic-inhibit-functions
(lambda () (not (member major-mode '(java-mode c-mode c++-mode)))))