Is it possible to show current #ifdef blocks in Emacs (eg in mode-line)?
For example:
#ifdef A
... | #cursor position num. 1
#ifdef !B & C
...
#else /* !B & C */
foo(); | #cursor position num. 2
#endif /* !B & C */
#endif /* A */
It should show A
in mode line, if I put cursor in position 1
and show A & !(!B & C)
in position 2.
I am already using hide-if-def mode. But sometimes i need to work with all #ifdef blocks.
I've not always had success with WhichFunction, but it should work with C/C++ code nicely. This customization will add a new function to the recognition scheme which will tell you when you're inside an #ifdef block.
(require 'which-func)
(which-function-mode 1)
(defun name-of-current-conditional ()
"rather inelegant coding, but it works"
(interactive)
(let (outer)
(condition-case nil
(dotimes (myv 10)
(save-excursion
(c-up-conditional (1+ myv))
(setq outer (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))))
(error nil))
outer))
(setq which-func-functions '(name-of-current-conditional))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With