From d9d4ff91e335f3c67a204b3e5cf9b9bdf1c164bf Mon Sep 17 00:00:00 2001 From: Alexandre Tuleu Date: Wed, 18 Dec 2024 10:31:23 +0100 Subject: [PATCH] Formats cmake file only if a project-wide configuration file is found Otherwise do nothing. --- .emacs | 56 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/.emacs b/.emacs index de83dca..0d21d3d 100644 --- a/.emacs +++ b/.emacs @@ -473,33 +473,41 @@ (defun atu/cmake-format-buffer () "Formats the current buffer using cmake-format" (interactive) - (let ((error-buffer (atu/create-or-erase-buffer "*cmake-format:stderr*"))) + (let ( + (error-buffer (atu/create-or-erase-buffer "*cmake-format:stderr*")) + (cmake-format-config-file-exists + (file-exists-p (projectile-expand-root ".cmake-format.yaml")) + ) + ) (setq-local atu/after-save-message nil) - (if (eq 0 (call-process-region - ;;region - (point-min) - (point-max) - "cmake-format" - nil ;do not delete buffer - ;; discard stdout copy stderr to buffer - error-buffer - nil ;dont-redisplay buffer - "-" - )) - (let ((current-point (point))) - (call-process-region - (point-min) (point-max) - "cmake-format" - t t t; replace current buffer and redisplay it - "--log-level=error" "-" + (if cmake-format-config-file-exists + (if (eq 0 (call-process-region + ;;region + (point-min) + (point-max) + "cmake-format" + nil ;do not delete buffer + ;; discard stdout copy stderr to buffer + error-buffer + nil ;dont-redisplay buffer + "-" + )) + (let ((current-point (point))) + (call-process-region + (point-min) (point-max) + "cmake-format" + t t t; replace current buffer and redisplay it + "--log-level=error" "-" + ) + (goto-char (+ (point-min) current-point)) + nil ) - (goto-char (+ (point-min) current-point)) - nil + (message + "cmake-format: could not format %s see buffer %s for details" + (buffer-name) error-buffer) + (current-message) ) - (message - "cmake-format: could not format %s see buffer %s for details" - (buffer-name) error-buffer) - (current-message) + (message "cmake-format: skipping as no configuration file found") ) ) )