C: Fix uncrustify support
parent
b2eabbb9e2
commit
214a56aaf7
|
@ -82,23 +82,26 @@ If the command is not `make', run it normally. "
|
|||
(compile (format "%s -B" compile-command))
|
||||
(recompile))))
|
||||
|
||||
(defun ambrevar/cc-format-with-uncrustify (&optional cfg-file)
|
||||
(defun ambrevar/cc-format-with-uncrustify (&optional cfg-file start end)
|
||||
"Run uncrustify(1) on current buffer or region."
|
||||
(interactive)
|
||||
(let (status
|
||||
start end
|
||||
(formatbuf (get-buffer-create "*C format buffer*")))
|
||||
(if (use-region-p)
|
||||
(setq start (region-beginning) end (region-end))
|
||||
(setq start (point-min) end (point-max)))
|
||||
(interactive "f\nr")
|
||||
(let (status
|
||||
(start (or (and (region-active-p) start)
|
||||
(point-min)))
|
||||
(end (or (and (region-active-p) end)
|
||||
(point-max)))
|
||||
(formatbuf (get-buffer-create " *C format buffer*")))
|
||||
(setq status
|
||||
(call-process-region start end "uncrustify" nil formatbuf nil "-lc" "-q" "-c"
|
||||
(or cfg-file
|
||||
(expand-file-name ".uncrustify.cfg" (getenv "HOME")))))
|
||||
(if (/= status 0)
|
||||
(error "error running uncrustify")
|
||||
(delete-region start end)
|
||||
(insert-buffer-substring formatbuf)
|
||||
(let ((old-point (point)))
|
||||
(save-mark-and-excursion
|
||||
(delete-region (or start (point-min)) (or end (point-max)))
|
||||
(insert-buffer-substring formatbuf))
|
||||
(goto-char old-point))
|
||||
(kill-buffer formatbuf))))
|
||||
|
||||
(defun ambrevar/cc-format-file-lookup ()
|
||||
|
@ -128,7 +131,7 @@ This is suitable for a `before-save-hook'."
|
|||
((and (string= (file-name-base cfg-file) ".clang-format")
|
||||
(require 'clang-format nil 'noerror))
|
||||
(clang-format-buffer))
|
||||
((and (string= (file-name-base cfg-file) ".uncrustify.cfg")
|
||||
((and (string= (file-name-base cfg-file) ".uncrustify")
|
||||
(executable-find "uncrustify"))
|
||||
(ambrevar/cc-format-with-uncrustify cfg-file)))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue