[LINT] Linted files + Added lint job to CI
This commit is contained in:
committed by
Radosław Gliński
parent
e8afad8f8a
commit
b9061e6292
68
third_party/clang-format/clang-format.el
vendored
68
third_party/clang-format/clang-format.el
vendored
@@ -1,7 +1,9 @@
|
||||
;;; clang-format.el --- Format code using clang-format -*- lexical-binding: t; -*-
|
||||
|
||||
;; Version: 0.1.0
|
||||
;; Keywords: tools, c
|
||||
;; Package-Requires: ((cl-lib "0.3"))
|
||||
;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
@@ -45,17 +47,29 @@ A string containing the name or the full path of the executable."
|
||||
:type '(file :must-match t)
|
||||
:risky t)
|
||||
|
||||
(defcustom clang-format-style "file"
|
||||
(defcustom clang-format-style nil
|
||||
"Style argument to pass to clang-format.
|
||||
|
||||
By default clang-format will load the style configuration from
|
||||
a file named .clang-format located in one of the parent directories
|
||||
of the buffer."
|
||||
:group 'clang-format
|
||||
:type 'string
|
||||
:type '(choice (string) (const nil))
|
||||
:safe #'stringp)
|
||||
(make-variable-buffer-local 'clang-format-style)
|
||||
|
||||
(defcustom clang-format-fallback-style "none"
|
||||
"Fallback style to pass to clang-format.
|
||||
|
||||
This style will be used if clang-format-style is set to \"file\"
|
||||
and no .clang-format is found in the directory of the buffer or
|
||||
one of parent directories. Set to \"none\" to disable formatting
|
||||
in such buffers."
|
||||
:group 'clang-format
|
||||
:type 'string
|
||||
:safe #'stringp)
|
||||
(make-variable-buffer-local 'clang-format-fallback-style)
|
||||
|
||||
(defun clang-format--extract (xml-node)
|
||||
"Extract replacements and cursor information from XML-NODE."
|
||||
(unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
|
||||
@@ -69,7 +83,7 @@ of the buffer."
|
||||
(let* ((children (xml-node-children node))
|
||||
(text (car children)))
|
||||
(cl-case (xml-node-name node)
|
||||
('replacement
|
||||
(replacement
|
||||
(let* ((offset (xml-get-attribute-or-nil node 'offset))
|
||||
(length (xml-get-attribute-or-nil node 'length)))
|
||||
(when (or (null offset) (null length))
|
||||
@@ -80,7 +94,7 @@ of the buffer."
|
||||
(setq offset (string-to-number offset))
|
||||
(setq length (string-to-number length))
|
||||
(push (list offset length text) replacements)))
|
||||
('cursor
|
||||
(cursor
|
||||
(setq cursor (string-to-number text)))))))
|
||||
|
||||
;; Sort by decreasing offset, length.
|
||||
@@ -119,10 +133,12 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding."
|
||||
(byte-to-position (1+ byte)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun clang-format-region (start end &optional style)
|
||||
(defun clang-format-region (start end &optional style assume-file-name)
|
||||
"Use clang-format to format the code between START and END according to STYLE.
|
||||
If called interactively uses the region or the current statement if there
|
||||
is no active region. If no style is given uses `clang-format-style'."
|
||||
If called interactively uses the region or the current statement if there is no
|
||||
no active region. If no STYLE is given uses `clang-format-style'. Use
|
||||
ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given
|
||||
uses the function `buffer-file-name'."
|
||||
(interactive
|
||||
(if (use-region-p)
|
||||
(list (region-beginning) (region-end))
|
||||
@@ -131,6 +147,9 @@ is no active region. If no style is given uses `clang-format-style'."
|
||||
(unless style
|
||||
(setq style clang-format-style))
|
||||
|
||||
(unless assume-file-name
|
||||
(setq assume-file-name (buffer-file-name (buffer-base-buffer))))
|
||||
|
||||
(let ((file-start (clang-format--bufferpos-to-filepos start 'approximate
|
||||
'utf-8-unix))
|
||||
(file-end (clang-format--bufferpos-to-filepos end 'approximate
|
||||
@@ -144,16 +163,22 @@ is no active region. If no style is given uses `clang-format-style'."
|
||||
;; always use ‘utf-8-unix’ and ignore the buffer coding system.
|
||||
(default-process-coding-system '(utf-8-unix . utf-8-unix)))
|
||||
(unwind-protect
|
||||
(let ((status (call-process-region
|
||||
nil nil clang-format-executable
|
||||
nil `(,temp-buffer ,temp-file) nil
|
||||
|
||||
"-output-replacements-xml"
|
||||
"-assume-filename" (or (buffer-file-name) "")
|
||||
"-style" style
|
||||
"-offset" (number-to-string file-start)
|
||||
"-length" (number-to-string (- file-end file-start))
|
||||
"-cursor" (number-to-string cursor)))
|
||||
(let ((status (apply #'call-process-region
|
||||
nil nil clang-format-executable
|
||||
nil `(,temp-buffer ,temp-file) nil
|
||||
`("-output-replacements-xml"
|
||||
;; Guard against a nil assume-file-name.
|
||||
;; If the clang-format option -assume-filename
|
||||
;; is given a blank string it will crash as per
|
||||
;; the following bug report
|
||||
;; https://bugs.llvm.org/show_bug.cgi?id=34667
|
||||
,@(and assume-file-name
|
||||
(list "-assume-filename" assume-file-name))
|
||||
,@(and style (list "-style" style))
|
||||
"-fallback-style" ,clang-format-fallback-style
|
||||
"-offset" ,(number-to-string file-start)
|
||||
"-length" ,(number-to-string (- file-end file-start))
|
||||
"-cursor" ,(number-to-string cursor))))
|
||||
(stderr (with-temp-buffer
|
||||
(unless (zerop (cadr (insert-file-contents temp-file)))
|
||||
(insert ": "))
|
||||
@@ -181,10 +206,13 @@ is no active region. If no style is given uses `clang-format-style'."
|
||||
(when (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun clang-format-buffer (&optional style)
|
||||
"Use clang-format to format the current buffer according to STYLE."
|
||||
(defun clang-format-buffer (&optional style assume-file-name)
|
||||
"Use clang-format to format the current buffer according to STYLE.
|
||||
If no STYLE is given uses `clang-format-style'. Use ASSUME-FILE-NAME
|
||||
to locate a style config file. If no ASSUME-FILE-NAME is given uses
|
||||
the function `buffer-file-name'."
|
||||
(interactive)
|
||||
(clang-format-region (point-min) (point-max) style))
|
||||
(clang-format-region (point-min) (point-max) style assume-file-name))
|
||||
|
||||
;;;###autoload
|
||||
(defalias 'clang-format 'clang-format-region)
|
||||
|
||||
Reference in New Issue
Block a user