Enables projectile switching between C/C++ files

This commit is contained in:
2023-10-05 12:31:59 +02:00
parent 4cbf8c3088
commit c944c410c4

67
.emacs
View File

@@ -511,6 +511,73 @@
:test "ng test --progress=false" :test "ng test --progress=false"
:run "ng serve" :run "ng serve"
:test-suffix ".spec") :test-suffix ".spec")
(defun atu/cmake-cc-inference (dir)
"Detects if the current root is a CMake C/C++ project"
(let ((cmakelists-file (projectile-expand-root "CMakeLists.txt" dir)))
(if (file-exists-p cmakelists-file)
(with-temp-buffer
(insert-file-contents cmakelists-file)
(goto-char (point-min))
(re-search-forward "project[[:space:]]*([^)]+\\([[:space:]]C\\(XX\\)?[[:space:]]\\)[^)]+)" nil t)
)))
)
(defun atu/cc-related-files (path)
"Returns related files path for a C/C++ file for a given path"
(let* (
(ext (file-name-extension path))
(basename (file-name-base path))
(dirpath (file-name-directory path))
(impl-rx "\\([.-]?[Ii]mp[l]?\\)$")
)
(if (member ext '("h" "hh" "hpp"))
(if (string-match impl-rx basename)
(list :other (concat dirpath
(string-replace
(match-string 1 basename)
""
basename)
"."
ext))
(list :other
(mapcar (lambda (sfx) (concat dirpath basename sfx))
(list
(concat "Imp." ext)
(concat "Impl." ext)
(concat "imp." ext)
(concat "impl." ext)
(concat ".Imp." ext)
(concat ".Impl." ext)
(concat ".imp." ext)
(concat ".impl." ext)
(concat "-Imp." ext)
(concat "-Impl." ext)
(concat "-imp." ext)
(concat "-impl." ext)
".cpp"
)))
)
(when (member ext '("c" "cc" "cpp"))
(list :other
(mapcar (lambda (sfx) (concat dirpath basename sfx))
'( ".h" ".hh" ".hpp" )))
)
)
)
)
(projectile-register-project-type 'cmake-cc #'atu/cmake-cc-inference
:project-file "CMakeLists.txt"
:configure "cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=On"
:compile "cmake --build build"
:test "cmake --build build --target check"
:related-files-fn
(list
#'atu/cc-related-files
(projectile-related-files-fn-test-with-suffix "cpp" "Test")
(projectile-related-files-fn-test-with-suffix "cpp" "UTest")
)
)
) )
(use-package vterm) (use-package vterm)