Skip to content

Instantly share code, notes, and snippets.

@inlinechan
Created May 18, 2016 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inlinechan/c8ae5a2ace0c4bd8f774c843d6ed9f85 to your computer and use it in GitHub Desktop.
Save inlinechan/c8ae5a2ace0c4bd8f774c843d6ed9f85 to your computer and use it in GitHub Desktop.
parse-compdb.el
;;; package --- Summary
;;; Commentary:
;;; Code:
(defun parse-compdb (db file)
"Parse compilation database DB of FILE and return list of include path."
(when (file-exists-p db)
(with-temp-buffer
(insert-file-contents db)
(goto-char (point-min))
(let ((end (search-forward file))
(begin (search-backward "\"command\":")))
;; (list begin end)
(get-include-path-list begin end)
))
)
)
(defun get-include-path-list (begin end)
"Parse from BEGIN to END and return list of include path."
(let ((result nil)
(current begin))
(while (and current (< current end))
(setq current (re-search-forward "-I[A-Za-z0-9-_/.]+" end t))
(if (null result)
(setq result (list (match-string 0)))
(add-to-list 'result (match-string 0))))
result))
(parse-compdb "/home/hyungchan/source/rtags/build/compile_commands.json"
"/home/hyungchan/source/rtags/src/rc.cpp")
(provide 'parse-compdb)
;;; parse-compdb.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment