문제

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)))))

다른 팁

I'm guessing the key lies in the global word. So use semantic-stickyfunc-mode instead of global-semantic-stickyfunc-mode etc.

UPDATE:

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top