Formats cmake file only if a project-wide configuration file is found
Otherwise do nothing.
This commit is contained in:
56
.emacs
56
.emacs
@@ -473,33 +473,41 @@
|
|||||||
(defun atu/cmake-format-buffer ()
|
(defun atu/cmake-format-buffer ()
|
||||||
"Formats the current buffer using cmake-format"
|
"Formats the current buffer using cmake-format"
|
||||||
(interactive)
|
(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)
|
(setq-local atu/after-save-message nil)
|
||||||
(if (eq 0 (call-process-region
|
(if cmake-format-config-file-exists
|
||||||
;;region
|
(if (eq 0 (call-process-region
|
||||||
(point-min)
|
;;region
|
||||||
(point-max)
|
(point-min)
|
||||||
"cmake-format"
|
(point-max)
|
||||||
nil ;do not delete buffer
|
"cmake-format"
|
||||||
;; discard stdout copy stderr to buffer
|
nil ;do not delete buffer
|
||||||
error-buffer
|
;; discard stdout copy stderr to buffer
|
||||||
nil ;dont-redisplay buffer
|
error-buffer
|
||||||
"-"
|
nil ;dont-redisplay buffer
|
||||||
))
|
"-"
|
||||||
(let ((current-point (point)))
|
))
|
||||||
(call-process-region
|
(let ((current-point (point)))
|
||||||
(point-min) (point-max)
|
(call-process-region
|
||||||
"cmake-format"
|
(point-min) (point-max)
|
||||||
t t t; replace current buffer and redisplay it
|
"cmake-format"
|
||||||
"--log-level=error" "-"
|
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))
|
(message
|
||||||
nil
|
"cmake-format: could not format %s see buffer %s for details"
|
||||||
|
(buffer-name) error-buffer)
|
||||||
|
(current-message)
|
||||||
)
|
)
|
||||||
(message
|
(message "cmake-format: skipping as no configuration file found")
|
||||||
"cmake-format: could not format %s see buffer %s for details"
|
|
||||||
(buffer-name) error-buffer)
|
|
||||||
(current-message)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user