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.