Question

For files with mixed types of programming languages, such as .html, semantic has trouble analyzing the code. Is there any way to specifically disable the auto analyzing by semantic for those types of files?

I am using the built-in cedet coming with Emacs 24:

CEDET Version:  1.0
            Requested   File        Loaded
  Package       Version     Version     Version
  ----------------------------------------------------------
  cedet:        1.0     nil     ok
  eieio:        1.3     nil     ok
  semantic:     2.0     nil     ok
  srecode:      1.0     nil     ok
  ede:          1.0     nil     ok
  speedbar:     1.0     nil     ok
Was it helpful?

Solution

Use semantic-inhibit-functions. For example, this:

(setq semantic-inhibit-functions
      (list (lambda () (not (and (featurep 'cc-defs)
                                 c-buffer-is-cc-mode)))))

should disable Semantic in all non-cc-mode buffers.

OTHER TIPS

Another example, to disable it for a specific mode:

(add-to-list 'semantic-inhibit-functions
             (lambda () (member major-mode '(html-mode))))

From Semantic docs:

2.3.1 Don't parse certain buffers

You can inhibit parsing using the semantic-inhibit-functions variable.

— Variable: semantic-inhibit-functions List of functions to call with no arguments before semantic sets up a buffer. If any of these functions returns non-nil, the current buffer is not setup to use Semantic.

You could have this inhibit parsing in very large files, or files which cause particular problems to semantic.

Proper usage example:

  ;; Disable Semantic's source referencing in lisp buffers.
  (add-hook 'semantic-inhibit-functions
            (lambda () (member major-mode '(emacs-lisp-mode))))

This adds it to the list (instead of overwriting the list), and ensures that it only runs after semantic has been loaded.

You must use with-eval-after-load, since the semantic package may not be loaded when your user config initializes. And in that case, you would get an error saying that the semantic-inhibit-functions variable doesn't exist, and your override wouldn't be applied.

This fixes those issues and is better than @Tom's and @Dmitry's answers.

Oh and I highly recommend blocking emacs-lisp-mode, because otherwise Semantic will try parsing the entire source code tree of the running Emacs instance whenever autocompletion is triggered, which will freeze Emacs if you have a lot of packages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top