0

How can I stop semantic-mode from clobbering buffer-local variables in derived modes? In my case I want semantic in C/C++, but I don't want it to setup in modes derived from these. Currently, I use semantic for the following

(setq semantic-new-buffer-setup-functions
      '((c-mode                . semantic-default-c-setup)
        (c++-mode              . semantic-default-c-setup)
        (srecode-template-mode . srecode-template-setup-parser)))

and attempt to disable it with

(add-to-list 'semantic-inhibit-functions
             (lambda () (not (memq major-mode '(c-mode c++-mode srecode-template-mode)))))

However, if I enter a derived mode, like bison-mode, semantic still runs its setup since it is hooked into c/c++, clobbering any variables I set in my bison-mode-hook, in this case imenu-create-index-function. How can I stop semantic from setting up derived modes?

Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • 2
    Instead of `memq`, use `derived-mode-p`. – Drew Feb 16 '18 at 01:40
  • `derived-mode-p` is true for the parent mode as well. Even if I disable `semantic-mode` in a mode's hook and define `imenu-create-index-function` in that same hook, it is still being set in the buffer – Rorschach Feb 16 '18 at 02:39
  • If you want only derived but not equal to the parent: `(and (derived-mode-p (not eq ...) ...))`. – Drew Feb 16 '18 at 02:52
  • but that function is supposed to return `t` for everything except those specific major modes. I don't think there is anything wrong with the way I have it. – Rorschach Feb 16 '18 at 02:57
  • Sorry, I meant `(and (derived-mode-p ...) (not (eq ...)) ...)`. – Drew Feb 16 '18 at 17:01
  • Sorry I think I worded it poorly, that function is supposed to be true for every mode except those three. The problem is semantic seems to clobber buffer-local variables when derived modes run parent mode hooks and I'm trying to figure a way around that – Rorschach Feb 16 '18 at 18:37
  • A major mode always kills all local variables when it is turned on. – Drew Feb 16 '18 at 21:34

0 Answers0