auto-complete-clang
auto-complete-clang copied to clipboard
Automatically generating system includes in Emacs
trafficstars
I just wrote this small elisp function that on Linux systems returns a list containing all the g++ system includes. This may horribly break on other platforms, but you may want to include it in your README.
(defun auto-complete-clang-get-system-includes ()
(with-temp-buffer
(shell-command
"echo | cpp -x c++ -Wp,-v 2>&1 | grep '^ .*include' | sed 's/^ //g'"
(current-buffer)
)
(split-string (buffer-string) "\n" t)
)
)
Thanks!
PS: I am still an elisp newbie, the whole with-temp-buffer thing can be replaced by shell-command-to-string. Much simpler. :)
Nice snippet, I'm using
(mapcar #'expand-file-name (split-string (shell-command-to-string "echo | gcc -x c++ -Wp,-v - 2>&1 | grep \"^ \"") "\n" t " "))
Note that gcc and clang have slightly different include paths (e.g. /usr/lib/gcc/.. vs /usr/lib/clang/..), it's better that you distinguish which one you really want.