[clang-tools-extra] r349150 - clang-include-fixer.el: support remote files

Philipp Stephani via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 14 05:56:05 PST 2018


Author: phst
Date: Fri Dec 14 05:56:05 2018
New Revision: 349150

URL: http://llvm.org/viewvc/llvm-project?rev=349150&view=rev
Log:
clang-include-fixer.el: support remote files

Summary: Support remote files (e.g., Tramp) in the Emacs integration for clang-include-fixer

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D54672

Modified:
    clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=349150&r1=349149&r2=349150&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Fri Dec 14 05:56:05 2018
@@ -93,8 +93,12 @@ temporary buffer, and CALLBACK is called
 buffer as only argument."
   (unless buffer-file-name
     (user-error "clang-include-fixer works only in buffers that visit a file"))
-  (let ((process (if (fboundp 'make-process)
-                     ;; Prefer using ‘make-process’ if available, because
+  (let ((process (if (and (fboundp 'make-process)
+                          ;; ‘make-process’ doesn’t support remote files
+                          ;; (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28691).
+                          (not (find-file-name-handler default-directory
+                                                       'start-file-process)))
+                     ;; Prefer using ‘make-process’ if possible, because
                      ;; ‘start-process’ doesn’t allow us to separate the
                      ;; standard error from the output.
                      (clang-include-fixer--make-process callback args)
@@ -125,7 +129,7 @@ arguments.  Return the new process objec
                   :stderr stderr)))
 
 (defun clang-include-fixer--start-process (callback args)
-  "Start a new clang-incude-fixer process using `start-process'.
+  "Start a new clang-incude-fixer process using `start-file-process'.
 CALLBACK is called after the process finishes successfully; it is
 called with a single argument, the buffer where standard output
 has been inserted.  ARGS is a list of additional command line
@@ -133,7 +137,7 @@ arguments.  Return the new process objec
   (let* ((stdin (current-buffer))
          (stdout (generate-new-buffer "*clang-include-fixer output*"))
          (process-connection-type nil)
-         (process (apply #'start-process "clang-include-fixer" stdout
+         (process (apply #'start-file-process "clang-include-fixer" stdout
                          (clang-include-fixer--command args))))
     (set-process-coding-system process 'utf-8-unix 'utf-8-unix)
     (set-process-query-on-exit-flag process nil)
@@ -156,7 +160,7 @@ file name; prepends ARGS directly in fro
     ,(format "-input=%s" clang-include-fixer-init-string)
     "-stdin"
     , at args
-    ,(buffer-file-name)))
+    ,(clang-include-fixer--file-local-name buffer-file-name)))
 
 (defun clang-include-fixer--sentinel (stdin stdout stderr callback)
   "Return a process sentinel for clang-include-fixer processes.
@@ -446,5 +450,11 @@ non-nil.  Otherwise return nil."
 (defalias 'clang-include-fixer--format-message
   (if (fboundp 'format-message) 'format-message 'format))
 
+;; ‘file-local-name’ is new in Emacs 26.1.  Provide a fallback for older
+;; versions.
+(defalias 'clang-include-fixer--file-local-name
+  (if (fboundp 'file-local-name) #'file-local-name
+    (lambda (file) (or (file-remote-p file 'localname) file))))
+
 (provide 'clang-include-fixer)
 ;;; clang-include-fixer.el ends here




More information about the cfe-commits mailing list