branch: scratch/editorconfig-cc commit d7c6a8befd4143aea671074ce839ac80ca1619c3 Author: Hong Xu <h...@topbug.net> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Reidentation for all *.el files. --- editorconfig-conf-mode.el | 60 +++++------ editorconfig-core-handle.el | 174 +++++++++++++++--------------- editorconfig-core.el | 90 ++++++++-------- editorconfig-fnmatch.el | 254 ++++++++++++++++++++++---------------------- 4 files changed, 289 insertions(+), 289 deletions(-) diff --git a/editorconfig-conf-mode.el b/editorconfig-conf-mode.el index e7bf53e014..f544bfaf9e 100644 --- a/editorconfig-conf-mode.el +++ b/editorconfig-conf-mode.el @@ -43,50 +43,50 @@ "Major mode for editing .editorconfig files." (set-variable 'indent-line-function 'indent-relative) (let ((key-property-list - '("charset" - "end_of_line" - "indent_size" - "indent_style" - "insert_final_newline" - "max_line_length" - "root" - "tab_width" - "trim_trailing_whitespace")) + '("charset" + "end_of_line" + "indent_size" + "indent_style" + "insert_final_newline" + "max_line_length" + "root" + "tab_width" + "trim_trailing_whitespace")) (key-value-list - '("true" - "false" - "lf" - "cr" - "crlf" - "space" - "tab" - "latin1" - "utf-8" - "utf-8-bom" - "utf-16be" - "utf-16le")) + '("true" + "false" + "lf" + "cr" + "crlf" + "space" + "tab" + "latin1" + "utf-8" + "utf-8-bom" + "utf-16be" + "utf-16le")) (font-lock-value - '(("^[ \t]*\\[\\(.+?\\)\\]" 1 font-lock-type-face) - ("^[ \t]*\\(.+?\\)[ \t]*[=:]" 1 font-lock-variable-name-face)))) + '(("^[ \t]*\\[\\(.+?\\)\\]" 1 font-lock-type-face) + ("^[ \t]*\\(.+?\\)[ \t]*[=:]" 1 font-lock-variable-name-face)))) ;; Highlight all key values (dolist (key-value key-value-list) (add-to-list - 'font-lock-value - `(,(format "[=:][ \t]*\\(%s\\)\\([ \t]\\|$\\)" key-value) - 1 font-lock-constant-face))) + 'font-lock-value + `(,(format "[=:][ \t]*\\(%s\\)\\([ \t]\\|$\\)" key-value) + 1 font-lock-constant-face))) ;; Highlight all key properties (dolist (key-property key-property-list) (add-to-list - 'font-lock-value - `(,(format "^[ \t]*\\(%s\\)[ \t]*[=:]" key-property) - 1 font-lock-builtin-face))) + 'font-lock-value + `(,(format "^[ \t]*\\(%s\\)[ \t]*[=:]" key-property) + 1 font-lock-builtin-face))) (conf-mode-initialize "#" font-lock-value))) ;;;###autoload (add-to-list 'auto-mode-alist - '("/\\.editorconfig\\'" . editorconfig-conf-mode)) + '("/\\.editorconfig\\'" . editorconfig-conf-mode)) (provide 'editorconfig-conf-mode) diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el index bfda7b92b8..42972a2e0d 100644 --- a/editorconfig-core-handle.el +++ b/editorconfig-core-handle.el @@ -68,20 +68,20 @@ If CONF does not exist return nil." (when (file-readable-p conf) (let ((cached (gethash conf - editorconfig-core-handle--cache-hash)) - (mtime (nth 5 - (file-attributes conf)))) + editorconfig-core-handle--cache-hash)) + (mtime (nth 5 + (file-attributes conf)))) (if (and cached - (equal (editorconfig-core-handle-mtime cached) - mtime)) - cached + (equal (editorconfig-core-handle-mtime cached) + mtime)) + cached (let ((parsed (editorconfig-core-handle--parse-file conf))) (puthash conf - (make-editorconfig-core-handle :top-prop (car parsed) - :prop (cdr parsed) - :mtime mtime - :path conf) - editorconfig-core-handle--cache-hash)))))) + (make-editorconfig-core-handle :top-prop (car parsed) + :prop (cdr parsed) + :mtime mtime + :path conf) + editorconfig-core-handle--cache-hash)))))) (defun editorconfig-core-handle-root-p (handle) "Return non-nil if HANDLE represent root EditorConfig file. @@ -89,9 +89,9 @@ If CONF does not exist return nil." If HANDLE is nil return nil." (when handle (string-equal "true" - (downcase (or (cdr (assoc "root" - (editorconfig-core-handle-top-prop handle))) - ""))))) + (downcase (or (cdr (assoc "root" + (editorconfig-core-handle-top-prop handle))) + ""))))) (defun editorconfig-core-handle-get-properties (handle file) "Return list of alist of properties from HANDLE for FILE. @@ -100,11 +100,11 @@ The list returned will be ordered by the lines they appear. If HANDLE is nil return nil." (when handle (mapcar (lambda (prop) (copy-alist (cdr prop))) - (cl-remove-if-not (lambda (prop) - (editorconfig-core-handle--fnmatch-p file - (car prop) - (file-name-directory (editorconfig-core-handle-path handle)))) - (editorconfig-core-handle-prop handle))))) + (cl-remove-if-not (lambda (prop) + (editorconfig-core-handle--fnmatch-p file + (car prop) + (file-name-directory (editorconfig-core-handle-path handle)))) + (editorconfig-core-handle-prop handle))))) (defun editorconfig-core-handle--fnmatch-p (name pattern dir) "Return non-nil if NAME match PATTERN. @@ -112,24 +112,24 @@ If pattern has slash, pattern should be relative to DIR. This function is a fnmatch with a few modification for EditorConfig usage." (if (string-match-p "/" pattern) - (let ((pattern (replace-regexp-in-string "^/" - "" - pattern)) - (dir (file-name-as-directory dir))) - (editorconfig-fnmatch-p name - (concat dir - pattern))) + (let ((pattern (replace-regexp-in-string "^/" + "" + pattern)) + (dir (file-name-as-directory dir))) + (editorconfig-fnmatch-p name + (concat dir + pattern))) (editorconfig-fnmatch-p name - (concat "**/" - pattern)))) + (concat "**/" + pattern)))) (defsubst editorconfig-core-handle--string-trim (str) "Remove leading and trailing whitespace from STR." (replace-regexp-in-string "[ \t\n\r]+\\'" - "" - (replace-regexp-in-string "\\`[ \t\n\r]+" - "" - str))) + "" + (replace-regexp-in-string "\\`[ \t\n\r]+" + "" + str))) (defun editorconfig-core-handle--parse-file (conf) "Parse EditorConfig file CONF. @@ -146,76 +146,76 @@ If CONF is not found return nil." (insert-file-contents conf) (goto-char (point-min)) (let ((point-max (point-max)) - (all-props ()) - (top-props nil) - - ;; String of current line - (line "") - ;; nil when pattern not appeared yet, "" when pattern is empty ("[]") - (pattern nil) - ;; Alist of properties for current PATTERN - (props ()) - - ;; Current line num - (current-line-number 1) - ) + (all-props ()) + (top-props nil) + + ;; String of current line + (line "") + ;; nil when pattern not appeared yet, "" when pattern is empty ("[]") + (pattern nil) + ;; Alist of properties for current PATTERN + (props ()) + + ;; Current line num + (current-line-number 1) + ) (while (not (eq (point) point-max)) (setq line - (buffer-substring-no-properties (point-at-bol) - (point-at-eol))) + (buffer-substring-no-properties (point-at-bol) + (point-at-eol))) (setq line - (replace-regexp-in-string "\\(^\\| \\)\\(#\\|;\\).*$" - "" - (editorconfig-core-handle--string-trim line))) + (replace-regexp-in-string "\\(^\\| \\)\\(#\\|;\\).*$" + "" + (editorconfig-core-handle--string-trim line))) (cond - ((string-equal "" line) - nil) - - ((string-match "^\\[\\(.*\\)\\]$" - line) - (when pattern - (setq all-props - `(,@all-props (,pattern . ,props))) - (setq props nil)) - (setq pattern (match-string 1 line))) - - (t - (let ((idx (string-match "=\\|:" - line))) - (unless idx - (error "Error while reading config file: %s:%d:\n %s\n" - conf - current-line-number - line)) - (let ( - (key (downcase (editorconfig-core-handle--string-trim - (substring line - 0 - idx)))) - (value (editorconfig-core-handle--string-trim - (substring line - (1+ idx))))) - (when (and (< (length key) 51) - (< (length value) 256)) - (if pattern + ((string-equal "" line) + nil) + + ((string-match "^\\[\\(.*\\)\\]$" + line) + (when pattern + (setq all-props + `(,@all-props (,pattern . ,props))) + (setq props nil)) + (setq pattern (match-string 1 line))) + + (t + (let ((idx (string-match "=\\|:" + line))) + (unless idx + (error "Error while reading config file: %s:%d:\n %s\n" + conf + current-line-number + line)) + (let ( + (key (downcase (editorconfig-core-handle--string-trim + (substring line + 0 + idx)))) + (value (editorconfig-core-handle--string-trim + (substring line + (1+ idx))))) + (when (and (< (length key) 51) + (< (length value) 256)) + (if pattern (when (< (length pattern) 4097) (setq props - `(,@props (,key . ,value)))) - (setq top-props - `(,@top-props (,key . ,value)))))))) - ) + `(,@props (,key . ,value)))) + (setq top-props + `(,@top-props (,key . ,value)))))))) + ) (setq current-line-number - (1+ current-line-number)) + (1+ current-line-number)) ;; Use this code instead of goto-line for Lisp program (goto-char (point-min)) (forward-line (1- current-line-number)) ) (when pattern (setq all-props - `(,@all-props (,pattern . ,props)))) + `(,@all-props (,pattern . ,props)))) (cons top-props - all-props))))) + all-props))))) (provide 'editorconfig-core-handle) diff --git a/editorconfig-core.el b/editorconfig-core.el index e3f511e5b9..4f69c774f6 100644 --- a/editorconfig-core.el +++ b/editorconfig-core.el @@ -86,12 +86,12 @@ then the result will be (let ((result ())) (dolist (e alist) (let ((pair (assoc (car e) - result))) + result))) (if pair - (setcdr pair - (cdr e)) + (setcdr pair + (cdr e)) (setq result - `(,@result ,e))))) + `(,@result ,e))))) result)) (defun editorconfig-core--get-handles (dir confname &optional result) @@ -103,17 +103,17 @@ The list may contains nil when no file was found for directories. RESULT is used internally and normally should not be used." (setq dir (expand-file-name dir)) (let ((handle (editorconfig-core-handle (concat (file-name-as-directory dir) - confname))) - (parent (file-name-directory (directory-file-name dir)))) + confname))) + (parent (file-name-directory (directory-file-name dir)))) (if (or (string= parent - dir) - (and handle - (editorconfig-core-handle-root-p handle))) - (cons handle result) + dir) + (and handle + (editorconfig-core-handle-root-p handle))) + (cons handle result) (editorconfig-core--get-handles parent - confname - (cons handle - result))))) + confname + (cons handle + result))))) ;;;###autoload @@ -126,52 +126,52 @@ If need to specify config format version, give CONFVERSION. This functions returns alist of properties. Each element will look like '(KEY . VALUE) ." (setq file (expand-file-name (or file - buffer-file-name - (error "FILE is not given and `buffer-file-name' is nil")))) + buffer-file-name + (error "FILE is not given and `buffer-file-name' is nil")))) (setq confname (or confname - ".editorconfig")) + ".editorconfig")) (setq confversion (or confversion - "0.12.0")) + "0.12.0")) (let ((result (editorconfig-core--remove-duplicate - (apply 'append - (mapcar (lambda (handle) - (apply 'append - (editorconfig-core-handle-get-properties handle - file))) - (editorconfig-core--get-handles (file-name-directory file) - confname)))))) + (apply 'append + (mapcar (lambda (handle) + (apply 'append + (editorconfig-core-handle-get-properties handle + file))) + (editorconfig-core--get-handles (file-name-directory file) + confname)))))) (dolist (key '("end_of_line" "indent_style" "indent_size" - "insert_final_newline" "trim_trailing_whitespace" "charset")) + "insert_final_newline" "trim_trailing_whitespace" "charset")) (let ((pair (assoc key - result))) + result))) (when pair (setcdr pair - (downcase (cdr pair)))))) + (downcase (cdr pair)))))) ;; Add indent_size property (let ((p-indent-size (assoc "indent_size" result)) - (p-indent-style (assoc "indent_style" result))) + (p-indent-style (assoc "indent_style" result))) (when (and (not p-indent-size) - (string= (cdr p-indent-style) "tab") - ;; If VERSION < 0.9.0, indent_size should have no default value - (version<= "0.9.0" - confversion)) + (string= (cdr p-indent-style) "tab") + ;; If VERSION < 0.9.0, indent_size should have no default value + (version<= "0.9.0" + confversion)) (setq result - `(,@result ("indent_size" . "tab"))))) + `(,@result ("indent_size" . "tab"))))) ;; Add tab_width property (let ((p-indent-size (assoc "indent_size" result)) - (p-tab-width (assoc "tab_width" result))) + (p-tab-width (assoc "tab_width" result))) (when (and p-indent-size - (not p-tab-width) - (not (string= (cdr p-indent-size) "tab"))) + (not p-tab-width) + (not (string= (cdr p-indent-size) "tab"))) (setq result - `(,@result ("tab_width" . ,(cdr p-indent-size)))))) + `(,@result ("tab_width" . ,(cdr p-indent-size)))))) ;; Update indent-size property (let ((p-indent-size (assoc "indent_size" result)) - (p-tab-width (assoc "tab_width" result))) + (p-tab-width (assoc "tab_width" result))) (when (and p-indent-size - p-tab-width - (string= (cdr p-indent-size) "tab")) + p-tab-width + (string= (cdr p-indent-size) "tab")) (setcdr p-indent-size (cdr p-tab-width)))) result)) @@ -186,13 +186,13 @@ If need to specify config format version, give CONFVERSION. This function is almost same as `editorconfig-core-get-properties', but returns hash object instead." (let ((result (editorconfig-core-get-properties file - confname - confversion)) - (hash (make-hash-table :test 'equal))) + confname + confversion)) + (hash (make-hash-table :test 'equal))) (dolist (prop result) (puthash (intern (car prop)) - (cdr prop) - hash)) + (cdr prop) + hash)) hash)) (provide 'editorconfig-core) diff --git a/editorconfig-fnmatch.el b/editorconfig-fnmatch.el index adeaaed1ec..91765ca8f7 100644 --- a/editorconfig-fnmatch.el +++ b/editorconfig-fnmatch.el @@ -78,7 +78,7 @@ ;; START arg does not work as expected in this case (while (string-match regexp string) (setq num (1+ num) - string (substring string (match-end 0)))) + string (substring string (match-end 0)))) num)) ;;;###autoload @@ -127,11 +127,11 @@ be used: Translation result will be cached, so same translation will not be done twice." (let ((cached (gethash pattern - editorconfig-fnmatch--cache-hash))) + editorconfig-fnmatch--cache-hash))) (or cached - (puthash pattern - (editorconfig-fnmatch--do-translate pattern) - editorconfig-fnmatch--cache-hash)))) + (puthash pattern + (editorconfig-fnmatch--do-translate pattern) + editorconfig-fnmatch--cache-hash)))) (defun editorconfig-fnmatch--do-translate (pattern &optional nested) @@ -142,163 +142,163 @@ Set NESTED to t when this function is called from itself. This function is called from `editorconfig-fnmatch-translate', when no cached translation is found for PATTERN." (let ((index 0) - (length (length pattern)) - (brace-level 0) - (in-brackets nil) - ;; List of strings of resulting regexp - (result ()) - (is-escaped nil) - (matching-braces (= (editorconfig-fnmatch--match-num - editorconfig-fnmatch--left-brace-regexp - pattern) + (length (length pattern)) + (brace-level 0) + (in-brackets nil) + ;; List of strings of resulting regexp + (result ()) + (is-escaped nil) + (matching-braces (= (editorconfig-fnmatch--match-num + editorconfig-fnmatch--left-brace-regexp + pattern) (editorconfig-fnmatch--match-num - editorconfig-fnmatch--right-brace-regexp - pattern))) - (numeric-groups ()) + editorconfig-fnmatch--right-brace-regexp + pattern))) + (numeric-groups ()) - current-char - pos - has-slash - has-comma - num-range) + current-char + pos + has-slash + has-comma + num-range) (while (< index length) (if (and (not is-escaped) - (string-match "[^]\\*?[{},/\\-]+" - ;;(string-match "[^]\\*?[{},/\\-]+" "?.a") - pattern - index) - (eq index (match-beginning 0))) - (setq result `(,@result ,(regexp-quote (match-string 0 pattern))) - index (match-end 0) - is-escaped nil) + (string-match "[^]\\*?[{},/\\-]+" + ;;(string-match "[^]\\*?[{},/\\-]+" "?.a") + pattern + index) + (eq index (match-beginning 0))) + (setq result `(,@result ,(regexp-quote (match-string 0 pattern))) + index (match-end 0) + is-escaped nil) (setq current-char (aref pattern index) - index (1+ index)) + index (1+ index)) (cl-case current-char (?* - (setq pos index) - (if (and (< pos length) - (= (aref pattern pos) ?*)) - (setq result `(,@result ".*")) - (setq result `(,@result "[^/]*")))) + (setq pos index) + (if (and (< pos length) + (= (aref pattern pos) ?*)) + (setq result `(,@result ".*")) + (setq result `(,@result "[^/]*")))) (?? - (setq result `(,@result "."))) + (setq result `(,@result "."))) (?\[ - (if in-brackets - (setq result `(,@result "\\[")) - (setq pos index - has-slash nil) - (while (and (< pos length) - (not (= (aref pattern pos) ?\])) - (not has-slash)) - (if (and (= (aref pattern pos) ?/) - (not (= (aref pattern (- pos 1)) ?\\))) - (setq has-slash t) - (setq pos (1+ pos)))) - (if has-slash - (setq result `(,@result ,(concat "\\[" - (substring pattern - index - (1+ pos)) - "\\]")) - index (+ pos 2)) - (if (and (< index length) - (memq (aref pattern index) - '(?! ?^))) - (setq index (1+ index) - result `(,@result "[^")) - (setq result `(,@result "["))) - (setq in-brackets t)))) + (if in-brackets + (setq result `(,@result "\\[")) + (setq pos index + has-slash nil) + (while (and (< pos length) + (not (= (aref pattern pos) ?\])) + (not has-slash)) + (if (and (= (aref pattern pos) ?/) + (not (= (aref pattern (- pos 1)) ?\\))) + (setq has-slash t) + (setq pos (1+ pos)))) + (if has-slash + (setq result `(,@result ,(concat "\\[" + (substring pattern + index + (1+ pos)) + "\\]")) + index (+ pos 2)) + (if (and (< index length) + (memq (aref pattern index) + '(?! ?^))) + (setq index (1+ index) + result `(,@result "[^")) + (setq result `(,@result "["))) + (setq in-brackets t)))) (?- - (if in-brackets - (setq result `(,@result "-")) - (setq result `(,@result "\\-")))) + (if in-brackets + (setq result `(,@result "-")) + (setq result `(,@result "\\-")))) (?\] - (setq result `(,@result "]") - in-brackets nil)) + (setq result `(,@result "]") + in-brackets nil)) (?{ - (setq pos index - has-comma nil) - (while (and (or (and (< pos length) - (not (= (aref pattern pos) - ?}))) - is-escaped) - (not has-comma)) - (if (and (eq (aref pattern pos) - ?,) - (not is-escaped)) - (setq has-comma t) - (setq is-escaped (and (eq (aref pattern pos) - ?\\) - (not is-escaped)) - pos (1+ pos)))) - (if (and (not has-comma) - (< pos length)) - (let ((pattern-sub (substring pattern index pos))) - (setq num-range (string-match editorconfig-fnmatch--numeric-range-regexp - pattern-sub)) - (if num-range - (setq numeric-groups `(,@numeric-groups ,(mapcar 'string-to-number - (list (match-string 1 - pattern-sub) - (match-string 2 - pattern-sub)))) - result `(,@result "\\([+-]?[0-9]+\\)")) - (let ((inner (editorconfig-fnmatch--do-translate pattern-sub t))) - (setq result `(,@result ,(format "{%s}" - (car inner))) - numeric-groups `(,@numeric-groups ,@(nth 1 inner))))) - (setq index (1+ pos))) - (if matching-braces - (setq result `(,@result "\\(?:") - brace-level (1+ brace-level)) - (setq result `(,@result "{"))))) + (setq pos index + has-comma nil) + (while (and (or (and (< pos length) + (not (= (aref pattern pos) + ?}))) + is-escaped) + (not has-comma)) + (if (and (eq (aref pattern pos) + ?,) + (not is-escaped)) + (setq has-comma t) + (setq is-escaped (and (eq (aref pattern pos) + ?\\) + (not is-escaped)) + pos (1+ pos)))) + (if (and (not has-comma) + (< pos length)) + (let ((pattern-sub (substring pattern index pos))) + (setq num-range (string-match editorconfig-fnmatch--numeric-range-regexp + pattern-sub)) + (if num-range + (setq numeric-groups `(,@numeric-groups ,(mapcar 'string-to-number + (list (match-string 1 + pattern-sub) + (match-string 2 + pattern-sub)))) + result `(,@result "\\([+-]?[0-9]+\\)")) + (let ((inner (editorconfig-fnmatch--do-translate pattern-sub t))) + (setq result `(,@result ,(format "{%s}" + (car inner))) + numeric-groups `(,@numeric-groups ,@(nth 1 inner))))) + (setq index (1+ pos))) + (if matching-braces + (setq result `(,@result "\\(?:") + brace-level (1+ brace-level)) + (setq result `(,@result "{"))))) (?, - (if (and (> brace-level 0) - (not is-escaped)) - (setq result `(,@result "\\|")) - (setq result `(,@result "\\,")))) + (if (and (> brace-level 0) + (not is-escaped)) + (setq result `(,@result "\\|")) + (setq result `(,@result "\\,")))) (?} - (if (and (> brace-level 0) - (not is-escaped)) - (setq result `(,@result "\\)") - brace-level (- brace-level 1)) - (setq result `(,@result "}")))) + (if (and (> brace-level 0) + (not is-escaped)) + (setq result `(,@result "\\)") + brace-level (- brace-level 1)) + (setq result `(,@result "}")))) (?/ - (if (and (<= (+ index 3) - (length pattern)) - (string= (substring pattern index (+ index 3)) - "**/")) - (setq result `(,@result "\\(?:/\\|/.*/\\)") - index (+ index 3)) - (setq result `(,@result "/")))) + (if (and (<= (+ index 3) + (length pattern)) + (string= (substring pattern index (+ index 3)) + "**/")) + (setq result `(,@result "\\(?:/\\|/.*/\\)") + index (+ index 3)) + (setq result `(,@result "/")))) (t - (unless (= current-char + (unless (= current-char ?\\) - (setq result `(,@result ,(regexp-quote (char-to-string current-char))))))) + (setq result `(,@result ,(regexp-quote (char-to-string current-char))))))) (if (= current-char ?\\) - (progn (when is-escaped - (setq result `(,@result "\\\\"))) - (setq is-escaped (not is-escaped))) + (progn (when is-escaped + (setq result `(,@result "\\\\"))) + (setq is-escaped (not is-escaped))) (setq is-escaped nil)))) (unless nested (setq result `("^" ,@result "\\'"))) (list (mapconcat 'identity - result - "") - numeric-groups))) + result + "") + numeric-groups))) (provide 'editorconfig-fnmatch)