auto-complete-clang icon indicating copy to clipboard operation
auto-complete-clang copied to clipboard

Automatically generating system includes in Emacs

Open root42 opened this issue 13 years ago • 3 comments
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)
    )
  )

root42 avatar Jun 28 '12 14:06 root42

Thanks!

brianjcj avatar Jul 11 '12 13:07 brianjcj

PS: I am still an elisp newbie, the whole with-temp-buffer thing can be replaced by shell-command-to-string. Much simpler. :)

root42 avatar Aug 01 '12 09:08 root42

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.

joca-bt avatar Feb 02 '15 23:02 joca-bt