Will Lentz <Will_Lentz@...> writes:
> Semantic seems to know what #ifdef regions are enabled, and emacs has a
> command to shadow or hide a given #ifdef region.
> Is it possible to have semantic call hide-ifdef-block appropriately for
> each #ifdef in a file? or write a function to do so?
> If that's hard.. would it be easier to write a function to go to the end
> of the file, get a list of all defined symbols, then call
> hide-ifdef-define or hide-ifdef-define-alist appropriately?
Adding the preprocessor symbols Semantic knows to hide-ifdef-env is
straightforward. The only tricky bit is *when* to do that, since I'm not
sure when these symbols are known in the buffer. I noticed when putting
this in c-mode-hook it wouldn't always work.
Therefore, I think the best way is to advice 'hide-ifdefs':
(defadvice hide-ifdefs (before DE-semantic-set-ifdef-symbols () )
(let ((syms (semantic-lex-spp-macros))
(setq cur (symbol-name (pop syms)))
(cons (intern cur) t))))))
It may be that this does not work in the first initial hiding, but it
should when you call it interactively in the buffer (via 'C-c @ h')
Note that Semantic does not parse all included headers for preprocessor
symbols by default. If you would like to add some header you'd like to
parse for #defines, do this by calling
(semantic-add-system-include "/path/foo.h" 'c-mode)