emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 74bb693 21/40: Call Clang from the directory containing co


From: Dmitry Gutov
Subject: [elpa] master 74bb693 21/40: Call Clang from the directory containing compile_flags.txt
Date: Thu, 2 Jan 2020 18:57:03 -0500 (EST)

branch: master
commit 74bb6934eaae7affb5ec57599c3080736d5ad10c
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Call Clang from the directory containing compile_flags.txt
    
    #933
---
 company-clang.el | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/company-clang.el b/company-clang.el
index 55d9d9b..272dd8f 100644
--- a/company-clang.el
+++ b/company-clang.el
@@ -51,7 +51,10 @@ and `c-electric-colon', for automatic completion right after 
\">\" and
 (defcustom company-clang-use-compile-flags-txt nil
   "When non-nil, use flags from compile_flags.txt if present.
 
-The lines from that files will be appended to `company-clang-arguments'."
+The lines from that files will be appended to `company-clang-arguments'.
+
+And if such file is found, Clang is called from the directory containing
+it.  That allows the flags use relative file names within the project."
   :type 'boolean
   :safe 'booleanp)
 
@@ -265,12 +268,15 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
 
 (defun company-clang--arguments ()
   (let ((fname "compile_flags.txt")
-        (args company-clang-arguments))
+        (args company-clang-arguments)
+        current-dir-rel)
     (when company-clang-use-compile-flags-txt
       (let ((dir (locate-dominating-file default-directory fname)))
         (when dir
+          (setq current-dir-rel (file-relative-name default-directory dir))
+          (setq default-directory dir)
           (with-temp-buffer
-            (insert-file-contents (expand-file-name fname dir))
+            (insert-file-contents fname)
             (setq args
                   (append
                    args
@@ -278,7 +284,9 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
                                   (point-min) (point-max))
                                  "[\n\r]+"
                                  t
-                                 "[ \t]+")))))))
+                                 "[ \t]+"))))
+          (unless (equal current-dir-rel "./")
+            (push (format "-I%s" current-dir-rel) args)))))
     args))
 
 (defun company-clang--candidates (prefix callback)
@@ -288,13 +296,14 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
   (when (null company-clang--prefix)
     (company-clang-set-prefix (or (funcall company-clang-prefix-guesser)
                                   'none)))
-  (apply 'company-clang--start-process
-         prefix
-         callback
-         (company-clang--build-complete-args
-          (if (company-clang--check-version 4.0 9.0)
-              (point)
-            (- (point) (length prefix))))))
+  (let ((default-directory default-directory))
+    (apply 'company-clang--start-process
+           prefix
+           callback
+           (company-clang--build-complete-args
+            (if (company-clang--check-version 4.0 9.0)
+                (point)
+              (- (point) (length prefix)))))))
 
 (defun company-clang--prefix ()
   (if company-clang-begin-after-member-access



reply via email to

[Prev in Thread] Current Thread [Next in Thread]