Here's how I was able to work around this issue:
- I copied the
.clang-format
file from the remote location into my home directory.
- I wrote the following wrapper function to replace the
--assume-filename
argument with a path referring to a file with the same name in the home directory:
(defun my-clang-format-region ()
(interactive)
(let ((start (if (use-region-p) (region-beginning) (point)))
(end (if (use-region-p) (region-end) (point)))
(assumed-filename (if (file-remote-p buffer-file-name)
(concat (getenv "HOME") "/" (file-name-nondirectory buffer-file-name))
buffer-file-name)))
(clang-format-region start end clang-format-style assumed-filename)))
(global-set-key '[(control meta tab)] 'my-clang-format-region)
It seems that --assume-filename
can specify a path to a file that doesn't exist. All clang-format
seems to care about is the file's extension and directory path; it uses the directory path as a location to look for the .clang-format
file. If it doesn't find the file there, it looks in every ancestor directory starting from that location.
This worked for me with versions 9.0 and 10.0 of the clang-format
executable, and clang-format.el
version 20190824.2216 from melpa.
clang-format.el
from MELPA. I don't know anything about, but scanning this file shortly it looks like it doesn't support remote work. For example, it usescall-process-region
, which isn't aware of remote hosts. – Michael Albinustramp-call-process-region
andtramp-sh-handle-call-process-region
; both didn't work. As I understand it,tramp-mode
copies the remote file to a local directory under/var
; I've also tried placing.clang-format
under/var
to no avail. – Covicall-process-region
would need a counterpartprocess-file-region
, which doesn't exist. So one must write this function first. – Michael Albinusprocess-file-region
would be? – Covi