Home | History | Annotate | Download | only in clang-format

Lines Matching defs:format

1 ;;; clang-format.el --- Format code using clang-format
8 ;; This package allows to filter code through clang-format to fix its formatting.
9 ;; clang-format is a tool that formats C/C++/Obj-C code according to a set of
11 ;; Note that clang-format 3.4 or newer is required.
13 ;; clang-format.el is available via MELPA and can be installed via
15 ;; M-x package-install clang-format
21 ;; (require 'clang-format)
25 ;; You may also want to bind `clang-format-region' to a key:
27 ;; (global-set-key [C-M-tab] 'clang-format-region)
34 (defgroup clang-format nil
35 "Format code using clang-format."
38 (defcustom clang-format-executable
39 (or (executable-find "clang-format")
40 "clang-format")
41 "Location of the clang-format executable.
44 :group 'clang-format
48 (defcustom clang-format-style "file"
49 "Style argument to pass to clang-format.
51 By default clang-format will load the style configuration from
52 a file named .clang-format located in one of the parent directories
54 :group 'clang-format
57 (make-variable-buffer-local 'clang-format-style)
59 (defun clang-format--extract (xml-node)
64 (incomplete-format (xml-get-attribute xml-node 'incomplete_format))
93 (list replacements cursor (string= incomplete-format "true"))))
95 (defun clang-format--replace (offset length &optional text)
104 (defun clang-format-region (char-start char-end &optional style)
105 "Use clang-format to format the code between START and END according to STYLE.
107 is no active region. If no style is given uses `clang-format-style'."
114 (setq style clang-format-style))
119 (temp-buffer (generate-new-buffer " *clang-format-temp*"))
120 (temp-file (make-temp-file "clang-format")))
125 (point-min) (point-max) clang-format-executable
144 (error "(clang-format killed by signal %s%s)" status stderr))
146 (error "(clang-format failed with code %d%s)" status stderr)))
149 (setq operations (clang-format--extract (car (xml-parse-region)))))
153 (incomplete-format (nth 2 operations)))
156 (apply #'clang-format--replace rpl))
160 (message "%s" incomplete-format)
161 (if incomplete-format
162 (message "(clang-format: incomplete (syntax errors)%s)" stderr)
163 (message "(clang-format: success%s)" stderr))))
168 (defun clang-format-buffer (&optional style)
169 "Use clang-format to format the current buffer according to STYLE."
171 (clang-format-region (point-min) (point-max) style))
174 (defalias 'clang-format 'clang-format-region)
176 (provide 'clang-format)
177 ;;; clang-format.el ends here