+++ /dev/null
-This is the file .../info/dir, which contains the
-topmost node of the Info hierarchy, called (dir)Top.
-The first time you invoke Info you start off looking at this node.
-\1f
-File: dir, Node: Top This is the top of the INFO tree
-
- This (the Directory node) gives a menu of major topics.
- Typing "q" exits, "H" lists all Info commands, "d" returns here,
- "h" gives a primer for first-timers,
- "mEmacs<Return>" visits the Emacs manual, etc.
-
- In Emacs, you can click mouse button 2 on a menu item or cross reference
- to select it.
-
-* Menu:
-
-Emacs
-* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
+++ /dev/null
-;;; editorconfig-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*-
-;; Generated by the `loaddefs-generate' function.
-
-;; This file is part of GNU Emacs.
-
-;;; Code:
-
-(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path)))
-
-
-\f
-;;; Generated autoloads from editorconfig.el
-
-(defvar editorconfig-mode nil "\
-Non-nil if Editorconfig mode is enabled.
-See the `editorconfig-mode' command
-for a description of this minor mode.
-Setting this variable directly does not take effect;
-either customize it (see the info node `Easy Customization')
-or call the function `editorconfig-mode'.")
-(custom-autoload 'editorconfig-mode "editorconfig" nil)
-(autoload 'editorconfig-mode "editorconfig" "\
-Toggle EditorConfig feature.
-
-To disable EditorConfig in some buffers, modify
-`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'.
-
-This is a global minor mode. If called interactively, toggle the
-`Editorconfig mode' mode. If the prefix argument is positive, enable
-the mode, and if it is zero or negative, disable the mode.
-
-If called from Lisp, toggle the mode if ARG is `toggle'. Enable the
-mode if ARG is nil, omitted, or is a positive number. Disable the mode
-if ARG is a negative number.
-
-To check whether the minor mode is enabled in the current buffer,
-evaluate `(default-value \\='editorconfig-mode)'.
-
-The mode's hook is called both when the mode is enabled and when it is
-disabled.
-
-(fn &optional ARG)" t)
-(autoload 'editorconfig-version "editorconfig" "\
-Get EditorConfig version as string.
-
-If called interactively or if SHOW-VERSION is non-nil, show the
-version in the echo area and the messages buffer.
-
-(fn &optional SHOW-VERSION)" t)
-(register-definition-prefixes "editorconfig" '("editorconfig-"))
-
-\f
-;;; Generated autoloads from editorconfig-conf-mode.el
-
-(autoload 'editorconfig-conf-mode "editorconfig-conf-mode" "\
-Major mode for editing .editorconfig files.
-
-(fn)" t)
-(add-to-list 'auto-mode-alist '("\\.editorconfig\\'" . editorconfig-conf-mode))
-(register-definition-prefixes "editorconfig-conf-mode" '("editorconfig-conf-mode-"))
-
-\f
-;;; Generated autoloads from editorconfig-core.el
-
-(autoload 'editorconfig-core-get-nearest-editorconfig "editorconfig-core" "\
-Return path to .editorconfig file that is closest to DIRECTORY.
-
-(fn DIRECTORY)")
-(register-definition-prefixes "editorconfig-core" '("editorconfig-core-"))
-
-\f
-;;; Generated autoloads from editorconfig-core-handle.el
-
-(register-definition-prefixes "editorconfig-core-handle" '("editorconfig-core-handle"))
-
-\f
-;;; Generated autoloads from editorconfig-fnmatch.el
-
-(register-definition-prefixes "editorconfig-fnmatch" '("editorconfig-fnmatch-"))
-
-\f
-;;; Generated autoloads from editorconfig-tools.el
-
-(autoload 'editorconfig-apply "editorconfig-tools" "\
-Get and apply EditorConfig properties to current buffer.
-
-This function does not respect the values of `editorconfig-exclude-modes' and
-`editorconfig-exclude-regexps' and always applies available properties.
-Use `editorconfig-mode-apply' instead to make use of these variables." t)
-(autoload 'editorconfig-mode-apply "editorconfig-tools" "\
-Get and apply EditorConfig properties to current buffer.
-
-This function does nothing when the major mode is listed in
-`editorconfig-exclude-modes', or variable `buffer-file-name' matches
-any of regexps in `editorconfig-exclude-regexps'." t)
-(autoload 'editorconfig-find-current-editorconfig "editorconfig-tools" "\
-Find the closest .editorconfig file for current file." t)
-(autoload 'editorconfig-display-current-properties "editorconfig-tools" "\
-Display EditorConfig properties extracted for current buffer." t)
-(defalias 'describe-editorconfig-properties #'editorconfig-display-current-properties)
-(autoload 'editorconfig-format-buffer "editorconfig-tools" "\
-Format buffer according to .editorconfig indent_style and indent_width." t)
-\f
-;;; End of scraped data
-
-(provide 'editorconfig-autoloads)
-
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; no-native-compile: t
-;; coding: utf-8-emacs-unix
-;; End:
-
-;;; editorconfig-autoloads.el ends here
+++ /dev/null
-;;; editorconfig-conf-mode.el --- Major mode for editing .editorconfig files -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2024 EditorConfig Team
-
-;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
-;; or the CONTRIBUTORS file for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or (at your
-;; option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-;; Public License for more details.
-
-;; You should have received a copy of the GNU General Public License along with
-;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Major mode for editing .editorconfig files.
-
-;;; Code:
-
-(require 'conf-mode)
-
-(defvar editorconfig-conf-mode-syntax-table
- (let ((table (make-syntax-table conf-unix-mode-syntax-table)))
- (modify-syntax-entry ?\; "<" table)
- table)
- "Syntax table in use in `editorconfig-conf-mode' buffers.")
-
-(defvar editorconfig-conf-mode-abbrev-table nil
- "Abbrev table in use in `editorconfig-conf-mode' buffers.")
-(define-abbrev-table 'editorconfig-conf-mode-abbrev-table ())
-
-;;;###autoload
-(define-derived-mode editorconfig-conf-mode conf-unix-mode "Conf[EditorConfig]"
- "Major mode for editing .editorconfig files."
- (set-variable 'indent-line-function 'indent-relative)
- (let ((key-property-list
- '("charset"
- "end_of_line"
- "file_type_emacs"
- "file_type_ext"
- "indent_size"
- "indent_style"
- "insert_final_newline"
- "max_line_length"
- "root"
- "tab_width"
- "trim_trailing_whitespace"))
- (key-value-list
- '("unset"
- "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))))
-
- ;; Highlight all key values
- (dolist (key-value key-value-list)
- (push `(,(format "[=:][ \t]*\\(%s\\)\\([ \t]\\|$\\)" key-value)
- 1 font-lock-constant-face)
- font-lock-value))
- ;; Highlight all key properties
- (dolist (key-property key-property-list)
- (push `(,(format "^[ \t]*\\(%s\\)[ \t]*[=:]" key-property)
- 1 font-lock-builtin-face)
- font-lock-value))
-
- (conf-mode-initialize "#" font-lock-value)))
-
-;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.editorconfig\\'" . editorconfig-conf-mode))
-
-(provide 'editorconfig-conf-mode)
-;;; editorconfig-conf-mode.el ends here
+++ /dev/null
-;;; editorconfig-core-handle.el --- Handle Class for EditorConfig File -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
-
-;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
-;; Package: editorconfig
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors or
-;; https://github.com/editorconfig/editorconfig-emacs/blob/master/CONTRIBUTORS
-;; for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-;; See the GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Handle structures for EditorConfig config file. This library is used
-;; internally from editorconfig-core.el .
-
-;;; Code:
-
-(require 'cl-lib)
-(when (eval-when-compile (version< emacs-version "28.1"))
- ;; For `string-trim'
- (require 'subr-x))
-
-(require 'editorconfig-fnmatch)
-
-(defvar editorconfig-core-handle--cache-hash
- (make-hash-table :test 'equal)
- "Hash of EditorConfig filename and its `editorconfig-core-handle' instance.")
-
-(cl-defstruct editorconfig-core-handle-section
- "Structure representing one section in a .editorconfig file.
-
-Slots:
-
-`name'
- String of section name (glob string).
-
-`props'
- Alist of properties: (KEY . VALUE)."
- (name nil)
- (props nil))
-
-(defun editorconfig-core-handle-section-get-properties (section file)
- "Return properties alist when SECTION name match FILE.
-
-FILE should be a relative file name, relative to the directory where
-the `.editorconfig' file which has SECTION lives.
-If not match, return nil."
- (when (editorconfig-core-handle--fnmatch-p
- file (editorconfig-core-handle-section-name section))
- (editorconfig-core-handle-section-props section)))
-
-(cl-defstruct editorconfig-core-handle
- "Structure representing an .editorconfig file.
-
-Slots:
-`top-props'
- Alist of top properties like ((\"root\" . \"true\"))
-
-`sections'
- List of `editorconfig-core-handle-section' structure objects.
-
-`mtime'
- Last modified time of .editorconfig file.
-
-`path'
- Absolute path to .editorconfig file."
- (top-props nil)
- (sections nil)
- (mtime nil)
- (path nil))
-
-
-(defun editorconfig-core-handle (conf)
- "Return EditorConfig handle for CONF, which should be a file path.
-
-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))))
- (if (and cached
- (equal (editorconfig-core-handle-mtime cached) mtime))
- cached
- (let ((parsed (editorconfig-core-handle--parse-file conf)))
- (puthash conf parsed editorconfig-core-handle--cache-hash))))))
-
-(defun editorconfig-core-handle-root-p (handle)
- "Return non-nil if HANDLE represent root EditorConfig file.
-
-If HANDLE is nil return nil."
- (when handle
- (string-equal "true"
- (downcase (or (cdr (assoc "root"
- (editorconfig-core-handle-top-props handle)))
- "")))))
-
-(defun editorconfig-core-handle-get-properties (handle file)
- "Return list of alist of properties from HANDLE for FILE.
-The list returned will be ordered by the lines they appear.
-
-If HANDLE is nil return nil."
- (declare (obsolete editorconfig-core-handle-get-properties-hash "0.8.0"))
- (when handle
- (let* ((dir (file-name-directory (editorconfig-core-handle-path handle)))
- (file (file-relative-name file dir)))
- (cl-loop for section in (editorconfig-core-handle-sections handle)
- for props = (editorconfig-core-handle-section-get-properties
- section file)
- when props collect (copy-alist props)))))
-
-
-(defun editorconfig-core-handle-get-properties-hash (handle file)
- "Return hash of properties from HANDLE for FILE.
-
-If HANDLE is nil return nil."
- (when handle
- (let* ((hash (make-hash-table))
- (dir (file-name-directory (editorconfig-core-handle-path handle)))
- (file (file-relative-name file dir)))
- (dolist (section (editorconfig-core-handle-sections handle))
- (cl-loop for (key . value) in (editorconfig-core-handle-section-get-properties section file)
- do (puthash (intern key) value hash)))
- hash)))
-
-(defun editorconfig-core-handle--fnmatch-p (name pattern)
- "Return non-nil if NAME match PATTERN.
-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)))
- (editorconfig-fnmatch-p name pattern))
- ;; The match is not "anchored" so it can be either in the current dir or
- ;; in a subdir. Contrary to Zsh patterns, editorconfig's `**/foo' does
- ;; not match `foo', so we need to split the problem into two matches.
- (or (editorconfig-fnmatch-p name pattern)
- (editorconfig-fnmatch-p name (concat "**/" pattern)))))
-
-(defun editorconfig-core-handle--parse-file (conf)
- "Parse EditorConfig file CONF.
-
-This function returns a `editorconfig-core-handle'.
-If CONF is not found return nil."
- (when (file-readable-p conf)
- (with-temp-buffer
- ;; NOTE: Use this instead of insert-file-contents-literally to enable
- ;; code conversion
- (insert-file-contents conf)
- (goto-char (point-min))
- (let ((sections ())
- (top-props nil)
-
- ;; 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 (eobp))
- (skip-chars-forward " \t\f")
- (cond
- ((looking-at "\\(?:[#;].*\\)?$")
- nil)
-
- ;; Start of section
- ((looking-at "\\[\\(.*\\)\\][ \t]*\\(?:[#;].*\\)?$")
- (let ((newpattern (match-string 1)))
- (when pattern
- (push (make-editorconfig-core-handle-section
- :name pattern
- :props (nreverse props))
- sections))
- (setq props nil)
- (setq pattern newpattern)))
-
- ((looking-at "\\([^=: \t][^=:]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
- (let ((key (downcase (string-trim (match-string 1))))
- (value (match-string 2)))
- (if pattern
- (push `(,key . ,value)
- props)
- (push `(,key . ,value)
- top-props))))
-
- (t (error "Error while reading config file: %s:%d:\n %s\n"
- conf current-line-number
- (buffer-substring-no-properties (line-beginning-position)
- (line-end-position)))))
- (setq current-line-number (1+ current-line-number))
- (goto-char (point-min))
- (forward-line (1- current-line-number)))
- (when pattern
- (push (make-editorconfig-core-handle-section
- :name pattern
- :props (nreverse props))
- sections))
- (make-editorconfig-core-handle
- :top-props (nreverse top-props)
- :sections (nreverse sections)
- :mtime (nth 5 (file-attributes conf))
- :path conf)))))
-
-(provide 'editorconfig-core-handle)
-;;; editorconfig-core-handle.el ends here
+++ /dev/null
-;;; editorconfig-core.el --- EditorConfig Core library in Emacs Lisp -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2024 EditorConfig Team
-
-;; Author: EditorConfig Team <editorconfig@googlegroups.com>
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
-;; or the CONTRIBUTORS file for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or (at your
-;; option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-;; Public License for more details.
-
-;; You should have received a copy of the GNU General Public License along with
-;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; This library is one implementation of EditorConfig Core, which parses
-;; .editorconfig files and returns properties for given files.
-;; This can be used in place of, for example, editorconfig-core-c.
-
-
-;; Use from EditorConfig Emacs Plugin
-
-;; Emacs plugin (v0.5 or later) can utilize this implementation.
-;; By default, the plugin first search for any EditorConfig executable,
-;; and fallback to this library if not found.
-;; If you always want to use this library, add following lines to your init.el:
-
-;; (setq editorconfig-get-properties-function
-;; #'editorconfig-core-get-properties-hash)
-
-
-;; Functions
-
-;; editorconfig-core-get-properties (&optional file confname confversion)
-
-;; Get EditorConfig properties for FILE.
-
-;; If FILE is not given, use currently visiting file.
-;; Give CONFNAME for basename of config file other than .editorconfig.
-;; If need to specify config format version, give CONFVERSION.
-
-;; This functions returns alist of properties. Each element will look like
-;; (KEY . VALUE) .
-
-
-;; editorconfig-core-get-properties-hash (&optional file confname)
-
-;; Get EditorConfig properties for FILE.
-
-;; This function is almost same as `editorconfig-core-get-properties', but
-;; returns hash object instead.
-
-;;; Code:
-
-(require 'cl-lib)
-
-(require 'editorconfig-core-handle)
-
-(eval-when-compile
- (require 'subr-x))
-
-
-(defun editorconfig-core--get-handles (dir confname &optional result)
- "Get list of EditorConfig handlers for DIR from CONFNAME.
-
-In the resulting list, the handle for root config file comes first, and the
-nearest comes last.
-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))))
- (if (or (string= parent dir)
- (and handle (editorconfig-core-handle-root-p handle)))
- (cl-remove-if-not #'identity (cons handle result))
- (editorconfig-core--get-handles parent
- confname
- (cons handle result)))))
-
-;;;###autoload
-(defun editorconfig-core-get-nearest-editorconfig (directory)
- "Return path to .editorconfig file that is closest to DIRECTORY."
- (when-let* ((handle (car (last
- (editorconfig-core--get-handles directory
- ".editorconfig")))))
- (editorconfig-core-handle-path handle)))
-
-(defun editorconfig-core--hash-merge (into update)
- "Merge two hashes INTO and UPDATE.
-
-This is a destructive function, hash INTO will be modified.
-When the same key exists in both two hashes, values of UPDATE takes precedence."
- (maphash (lambda (key value) (puthash key value into)) update)
- into)
-
-(defun editorconfig-core-get-properties-hash (&optional file confname)
- "Get EditorConfig properties for FILE.
-If FILE is not given, use currently visiting file.
-Give CONFNAME for basename of config file other than .editorconfig.
-If need to specify config format version, give CONFVERSION.
-
-This function is almost same as `editorconfig-core-get-properties', but returns
-hash object instead."
- (setq file
- (expand-file-name (or file
- buffer-file-name
- (error "FILE is not given and `buffer-file-name' is nil"))))
- (setq confname (or confname ".editorconfig"))
- (let ((result (make-hash-table)))
- (dolist (handle (editorconfig-core--get-handles (file-name-directory file)
- confname))
- (editorconfig-core--hash-merge result
- (editorconfig-core-handle-get-properties-hash handle
- file)))
-
- ;; Downcase known boolean values
- ;; FIXME: Why not do that in `editorconfig-core-handle--parse-file'?
- (dolist (key '( end_of_line indent_style indent_size insert_final_newline
- trim_trailing_whitespace charset))
- (when-let* ((val (gethash key result)))
- (puthash key (downcase val) result)))
-
- result))
-
-(provide 'editorconfig-core)
-;;; editorconfig-core.el ends here
+++ /dev/null
-;;; editorconfig-fnmatch.el --- Glob pattern matching -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
-
-;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
-;; Package: editorconfig
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors or
-;; https://github.com/editorconfig/editorconfig-emacs/blob/master/CONTRIBUTORS
-;; for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-;; See the GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; editorconfig-fnmatch.el provides a fnmatch implementation with a few
-;; extensions.
-;; The main usage of this library is glob pattern matching for EditorConfig, but
-;; it can also act solely.
-
-;; editorconfig-fnmatch-p (name pattern)
-
-;; Test whether NAME match PATTERN.
-
-;; PATTERN should be a shell glob pattern, and some zsh-like wildcard matchings
-;; can be used:
-
-;; * Matches any string of characters, except path separators (/)
-;; ** Matches any string of characters
-;; ? Matches any single character
-;; [name] Matches any single character in name
-;; [^name] Matches any single character not in name
-;; {s1,s2,s3} Matches any of the strings given (separated by commas)
-;; {min..max} Matches any number between min and max
-
-
-;; This library is a port from editorconfig-core-py library.
-;; https://github.com/editorconfig/editorconfig-core-py/blob/master/editorconfig/fnmatch.py
-
-;;; Code:
-
-(require 'cl-lib)
-
-(defconst editorconfig-fnmatch--cache-hashtable ;; Clear cache on file reload.
- (make-hash-table :test 'equal)
- "Cache of shell pattern and its translation.")
-
-(defconst editorconfig-fnmatch--left-brace-regexp
- "\\(^\\|[^\\]\\){"
- "Regular expression for left brace ({).")
-
-(defconst editorconfig-fnmatch--right-brace-regexp
- "\\(^\\|[^\\]\\)}"
- "Regular expression for right brace (}).")
-
-
-(defconst editorconfig-fnmatch--numeric-range-regexp
- "\\([+-]?[0-9]+\\)\\.\\.\\([+-]?[0-9]+\\)"
- "Regular expression for numeric range (like {-3..+3}).")
-
-(defun editorconfig-fnmatch--match-num (regexp string)
- "Return how many times REGEXP is found in STRING."
- (let ((num 0))
- ;; 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))))
- num))
-
-(defun editorconfig-fnmatch-p (string pattern)
- "Test whether STRING match PATTERN.
-
-Matching ignores case if `case-fold-search' is non-nil.
-
-PATTERN should be a shell glob pattern, and some zsh-like wildcard matchings can
-be used:
-
-* Matches any string of characters, except path separators (/)
-** Matches any string of characters
-? Matches any single character
-[name] Matches any single character in name
-[^name] Matches any single character not in name
-{s1,s2,s3} Matches any of the strings given (separated by commas)
-{min..max} Matches any number between min and max"
- (string-match (editorconfig-fnmatch-translate pattern)
- string))
-
-;;(editorconfig-fnmatch-translate "{a,{-3..3}}.js")
-;;(editorconfig-fnmatch-p "1.js" "{a,{-3..3}}.js")
-
-(defun editorconfig-fnmatch-translate (pattern)
- "Translate a shell PATTERN to a regular expression.
-
-Translation result will be cached, so same translation will not be done twice."
- (let ((cached (gethash pattern
- editorconfig-fnmatch--cache-hashtable)))
- (or cached
- (puthash pattern
- (editorconfig-fnmatch--do-translate pattern)
- editorconfig-fnmatch--cache-hashtable))))
-
-
-(defun editorconfig-fnmatch--do-translate (pattern &optional nested)
- "Translate a shell PATTERN to a regular expression.
-
-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, in reverse order.
- (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)))
-
- 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)))
- (progn
- (push (regexp-quote (match-string 0 pattern)) result)
- (setq index (match-end 0)
- is-escaped nil))
-
- (setq current-char (aref pattern index)
- index (1+ index))
-
- (push
- (cl-case current-char
- (?*
- (setq pos index)
- (if (and (< pos length)
- (= (aref pattern pos) ?*))
- (progn
- (setq index (1+ index))
- ".*")
- "[^/]*"))
-
- (?? "[^/]")
-
- (?\[
- (if in-brackets
- "\\["
- (if (= (aref pattern index) ?/)
- ;; Slash after an half-open bracket
- (progn
- (setq index (+ index 1))
- "\\[/")
- (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
- (let ((content (substring pattern index (1+ pos))))
- (setq index (+ pos 2))
- (concat "\\[" content "\\]"))
- (setq in-brackets t)
- (if (and (< index length)
- (memq (aref pattern index)
- '(?! ?^)))
- (progn
- (setq index (1+ index))
- "[^")
- "[")))))
-
- (?\] (setq 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))
- (setq index (1+ pos))
- (if num-range
- (let ((number-start (string-to-number
- (match-string 1 pattern-sub)))
- (number-end (string-to-number
- (match-string 2 pattern-sub))))
- (regexp-opt
- (mapcar #'number-to-string
- (cl-loop for i from number-start to number-end
- collect i))))
- (let ((inner (editorconfig-fnmatch--do-translate
- pattern-sub t)))
- (format "{%s}" inner))))
- (if matching-braces
- (progn
- (setq brace-level (1+ brace-level))
- "\\(?:")
- "{")))
-
- (?,
- (if (and (> brace-level 0)
- (not is-escaped))
- "\\|" ","))
-
- (?\}
- (if (and (> brace-level 0)
- (not is-escaped))
- (progn
- (setq brace-level (- brace-level 1))
- "\\)")
- "}"))
-
- (?/
- (if (and (<= (+ index 3) (length pattern))
- (string= (substring pattern index (+ index 3)) "**/"))
- (progn
- (setq index (+ index 3))
- "\\(?:/\\|/.*/\\)")
- "/"))
-
- (?\\ (when is-escaped "\\\\"))
- (t (regexp-quote (char-to-string current-char))))
- result)
-
- (setq is-escaped (and (= current-char ?\\) (not is-escaped)))))
- (unless nested
- (setq result `("\\'" ,@result "\\`")))
- (apply #'concat (reverse result))))
-
-(provide 'editorconfig-fnmatch)
-;;; editorconfig-fnmatch.el ends here
+++ /dev/null
-;; -*- no-byte-compile: t; lexical-binding: nil -*-
-(define-package "editorconfig" "20251221.650"
- "EditorConfig Emacs Plugin."
- '((emacs "27.2"))
- :url "https://github.com/editorconfig/editorconfig-emacs#readme"
- :commit "6783cb2a9fb82dc152e633e2e40162c150a4e818"
- :revdesc "6783cb2a9fb8"
- :keywords '("convenience" "editorconfig")
- :authors '(("EditorConfig Team" . "editorconfigNOSPAMgooglegroups.com"))
- :maintainers '(("EditorConfig Team" . "editorconfigNOSPAMgooglegroups.com")))
+++ /dev/null
-;;; editorconfig-tools.el --- Editorconfig tools -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2024 EditorConfig Team
-
-;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
-;; or the CONTRIBUTORS file for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or (at your
-;; option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-;; Public License for more details.
-
-;; You should have received a copy of the GNU General Public License along with
-;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Some utility commands for users, not used from editorconfig-mode.
-
-;;; Code:
-
-(require 'cl-lib)
-
-(eval-when-compile
- (require 'subr-x))
-
-
-(require 'editorconfig)
-
-;;;###autoload
-(defun editorconfig-apply ()
- "Get and apply EditorConfig properties to current buffer.
-
-This function does not respect the values of `editorconfig-exclude-modes' and
-`editorconfig-exclude-regexps' and always applies available properties.
-Use `editorconfig-mode-apply' instead to make use of these variables."
- (interactive)
- (when buffer-file-name
- (condition-case err
- (progn
- (let ((props (editorconfig-call-get-properties-function buffer-file-name)))
- (condition-case err
- (run-hook-with-args 'editorconfig-hack-properties-functions props)
- (error
- (display-warning '(editorconfig editorconfig-hack-properties-functions)
- (format "Error while running editorconfig-hack-properties-functions, abort running hook: %S"
- err)
- :warning)))
- (setq editorconfig-properties-hash props)
- (editorconfig-set-local-variables props)
- (editorconfig-set-coding-system-revert
- (gethash 'end_of_line props)
- (gethash 'charset props))
- (condition-case err
- (run-hook-with-args 'editorconfig-after-apply-functions props)
- (error
- (display-warning '(editorconfig editorconfig-after-apply-functions)
- (format "Error while running editorconfig-after-apply-functions, abort running hook: %S"
- err)
- :warning)))))
- (error
- (display-warning '(editorconfig editorconfig-apply)
- (format "Error in editorconfig-apply, styles will not be applied: %S" err)
- :error)))))
-
-;;;###autoload
-(defun editorconfig-mode-apply ()
- "Get and apply EditorConfig properties to current buffer.
-
-This function does nothing when the major mode is listed in
-`editorconfig-exclude-modes', or variable `buffer-file-name' matches
-any of regexps in `editorconfig-exclude-regexps'."
- (interactive)
- (when (and major-mode
- (not (editorconfig--disabled-for-majormode major-mode))
- buffer-file-name
- (not (editorconfig--disabled-for-filename buffer-file-name)))
- (editorconfig-apply)))
-
-
-;;;###autoload
-(defun editorconfig-find-current-editorconfig ()
- "Find the closest .editorconfig file for current file."
- (interactive)
- (eval-and-compile (require 'editorconfig-core))
- (when-let* ((file (editorconfig-core-get-nearest-editorconfig
- default-directory)))
- (find-file file)))
-
-;;;###autoload
-(defun editorconfig-display-current-properties ()
- "Display EditorConfig properties extracted for current buffer."
- (interactive)
- (if editorconfig-properties-hash
- (let ((buf (get-buffer-create "*EditorConfig Properties*"))
- (file buffer-file-name)
- (props editorconfig-properties-hash))
- (with-current-buffer buf
- (erase-buffer)
- (insert (format "# EditorConfig for %s\n" file))
- (maphash (lambda (k v)
- (insert (format "%S = %s\n" k v)))
- props))
- (display-buffer buf))
- (message "Properties are not applied to current buffer yet.")
- nil))
-;;;###autoload
-(defalias 'describe-editorconfig-properties
- #'editorconfig-display-current-properties)
-
-;;;###autoload
-(defun editorconfig-format-buffer()
- "Format buffer according to .editorconfig indent_style and indent_width."
- (interactive)
- (when (string= (gethash 'indent_style editorconfig-properties-hash) "tab")
- (tabify (point-min) (point-max)))
- (when (string= (gethash 'indent_style editorconfig-properties-hash) "space")
- (untabify (point-min) (point-max)))
- (indent-region (point-min) (point-max)))
-
-
-(provide 'editorconfig-tools)
-;;; editorconfig-tools.el ends here
+++ /dev/null
-;;; editorconfig.el --- EditorConfig Emacs Plugin -*- lexical-binding: t -*-
-
-;; Copyright (C) 2011-2024 EditorConfig Team
-
-;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
-;; Package-Version: 20251221.650
-;; Package-Revision: 6783cb2a9fb8
-;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
-;; Package-Requires: ((emacs "27.2"))
-;; Keywords: convenience editorconfig
-
-;; See
-;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
-;; or the CONTRIBUTORS file for the list of contributors.
-
-;; This file is part of EditorConfig Emacs Plugin.
-
-;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or (at your
-;; option) any later version.
-
-;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-;; Public License for more details.
-
-;; You should have received a copy of the GNU General Public License along with
-;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; EditorConfig helps developers define and maintain consistent
-;; coding styles between different editors and IDEs.
-
-;; The EditorConfig project consists of a file format for defining
-;; coding styles and a collection of text editor plugins that enable
-;; editors to read the file format and adhere to defined styles.
-;; EditorConfig files are easily readable and they work nicely with
-;; version control systems.
-
-;;; Code:
-
-(require 'cl-lib)
-
-(eval-when-compile (require 'subr-x))
-(defvar tex-indent-basic)
-(defvar tex-indent-item)
-(defvar tex-indent-arg)
-(defvar evil-shift-width)
-
-(require 'editorconfig-core)
-
-(defgroup editorconfig nil
- "EditorConfig Emacs Plugin.
-
-EditorConfig helps developers define and maintain consistent
-coding styles between different editors and IDEs."
- :tag "EditorConfig"
- :prefix "editorconfig-"
- :group 'tools)
-
-(define-obsolete-variable-alias
- 'edconf-exec-path
- 'editorconfig-exec-path
- "0.5")
-(defcustom editorconfig-exec-path
- "editorconfig"
- "Path to EditorConfig executable.
-
-Used by `editorconfig--execute-editorconfig-exec'."
- :type 'string)
-
-(define-obsolete-variable-alias
- 'edconf-get-properties-function
- 'editorconfig-get-properties-function
- "0.5")
-(defcustom editorconfig-get-properties-function
- #'editorconfig-core-get-properties-hash
- "A function which gets EditorConfig properties for specified file.
-
-This function will be called with one argument, full path of the target file,
-and should return a hash object containing properties, or nil if any core
-program is not available. Keys of this hash should be symbols of properties,
-and values should be strings of their values.
-
-
-For example, if you always want to use built-in core library instead
-of any EditorConfig executable to get properties, add following to
-your init.el:
-
- (set-variable \\='editorconfig-get-properties-function
- #\\='editorconfig-core-get-properties-hash)
-
-Possible known values are:
-
-* `editorconfig-core-get-properties-hash' (default)
- * Always use built-in Emacs-Lisp implementation to get properties
-* `editorconfig-get-properties'
- * Use `editorconfig-get-properties-from-exec' when
- `editorconfig-exec-path' executable is found, otherwise
- use `editorconfig-core-get-properties-hash'
-* `editorconfig-get-properties-from-exec'
- * Get properties by executing EditorConfig executable"
- :type 'function)
-
-(defcustom editorconfig-mode-lighter " EditorConfig"
- "Command `editorconfig-mode' lighter string."
- :type 'string)
-
-(define-obsolete-variable-alias
- 'edconf-custom-hooks
- 'editorconfig-after-apply-functions
- "0.5")
-(define-obsolete-variable-alias
- 'editorconfig-custom-hooks
- 'editorconfig-after-apply-functions
- "0.7.14")
-(defcustom editorconfig-after-apply-functions ()
- "A list of functions after loading common EditorConfig settings.
-
-Each element in this list is a hook function. This hook function
-takes one parameter, which is a property hash table. The value
-of properties can be obtained through gethash function.
-
-The hook does not have to be coding style related; you can add
-whatever functionality you want. For example, the following is
-an example to add a new property emacs_linum to decide whether to
-show line numbers on the left:
-
- (add-hook \\='editorconfig-after-apply-functions
- \\='(lambda (props)
- (let ((show-line-num (gethash \\='emacs_linum props)))
- (cond ((equal show-line-num \"true\") (linum-mode 1))
- ((equal show-line-num \"false\") (linum-mode 0))))))
-
-This hook will be run even when there are no matching sections in
-\".editorconfig\", or no \".editorconfig\" file was found at all."
- :type 'hook)
-
-(defcustom editorconfig-hack-properties-functions ()
- "A list of function to alter property values before applying them.
-
-These functions will be run after loading \".editorconfig\" files and before
-applying them to current buffer, so that you can alter some properties from
-\".editorconfig\" before they take effect.
-\(Since 2021/08/30 (v0.9.0): Buffer coding-systems are set before running
-this functions, so this variable cannot be used to change coding-systems.)
-
-For example, Makefiles always use tab characters for indentation: you can
-overwrite \"indent_style\" property when current `major-mode' is a
-`makefile-mode' with following code:
-
- (add-hook \\='editorconfig-hack-properties-functions
- \\='(lambda (props)
- (when (derived-mode-p \\='makefile-mode)
- (puthash \\='indent_style \"tab\" props))))
-
-This hook will be run even when there are no matching sections in
-\".editorconfig\", or no \".editorconfig\" file was found at all."
- :type 'hook)
-(make-obsolete-variable 'editorconfig-hack-properties-functions
- "Using `editorconfig-after-apply-functions' instead is recommended,
- because since 2021/08/30 (v0.9.0) this variable cannot support all properties:
- charset values will be referenced before running this hook."
- "v0.9.0")
-
-(define-obsolete-variable-alias
- 'edconf-indentation-alist
- 'editorconfig-indentation-alist
- "0.5")
-(defcustom editorconfig-indentation-alist
- ;; For contributors: Sort modes in alphabetical order
- '((ada-mode ada-indent)
- (ada-ts-mode ada-ts-mode-indent-offset)
- (awk-mode c-basic-offset)
- (bash-ts-mode sh-basic-offset
- sh-indentation)
- (bpftrace-mode c-basic-offset)
- (c++-mode c-basic-offset)
- (c++-ts-mode c-basic-offset
- c-ts-mode-indent-offset)
- (c-ts-mode c-basic-offset
- c-ts-mode-indent-offset)
- (cmake-mode cmake-tab-width)
- (cmake-ts-mode cmake-tab-width
- cmake-ts-mode-indent-offset)
- (coffee-mode coffee-tab-width)
- (csharp-mode c-basic-offset)
- (csharp-ts-mode c-basic-offset
- csharp-ts-mode-indent-offset)
- (css-ts-mode css-indent-offset)
- (d-mode c-basic-offset)
- (elixir-ts-mode elixir-ts-indent-offset)
- (emacs-lisp-mode . editorconfig--get-indentation-lisp-mode)
- (f90-mode f90-associate-indent
- f90-continuation-indent
- f90-critical-indent
- f90-do-indent
- f90-if-indent
- f90-program-indent
- f90-type-indent)
- (feature-mode feature-indent-offset
- feature-indent-level)
- (fsharp-mode fsharp-continuation-offset
- fsharp-indent-level
- fsharp-indent-offset)
- (go-ts-mode go-ts-mode-indent-offset)
- (gpr-mode gpr-indent)
- (gpr-ts-mode gpr-ts-mode-indent-offset)
- (haskell-mode haskell-indent-spaces
- haskell-indent-offset
- haskell-indentation-layout-offset
- haskell-indentation-left-offset
- haskell-indentation-starter-offset
- haskell-indentation-where-post-offset
- haskell-indentation-where-pre-offset
- shm-indent-spaces)
- (haxor-mode haxor-tab-width)
- (html-ts-mode html-ts-mode-indent-offset)
- (idl-mode c-basic-offset)
- (jade-mode jade-tab-width)
- (java-mode c-basic-offset)
- (java-ts-mode c-basic-offset
- java-ts-mode-indent-offset)
- (js-ts-mode js-indent-level)
- (js-json-mode js-indent-level)
- (js-jsx-mode js-indent-level sgml-basic-offset)
- (js2-jsx-mode js2-basic-offset sgml-basic-offset)
- (json-mode js-indent-level)
- (json-ts-mode json-ts-mode-indent-offset)
- (jsonian-mode jsonian-default-indentation)
- (kotlin-mode kotlin-tab-width)
- (kotlin-ts-mode kotlin-ts-mode-indent-offset)
- (latex-mode . editorconfig--get-indentation-latex-mode)
- (lisp-mode . editorconfig--get-indentation-lisp-mode)
- (livescript-mode livescript-tab-width)
- (magik-ts-mode magik-indent-level)
- (meson-mode meson-indent-basic)
- (mips-mode mips-tab-width)
- (mustache-mode mustache-basic-offset)
- (nxml-mode . editorconfig--get-indentation-nxml-mode)
- (objc-mode c-basic-offset)
- (octave-mode octave-block-offset)
- ;; No need to change `php-mode-coding-style' value for php-mode
- ;; since we run editorconfig later than it resets `c-basic-offset'.
- ;; See https://github.com/editorconfig/editorconfig-emacs/issues/116
- ;; for details.
- (php-mode c-basic-offset)
- (php-ts-mode php-ts-mode-indent-offset)
- (pike-mode c-basic-offset)
- (protobuf-mode c-basic-offset)
- (ps-mode ps-mode-tab)
- (pug-mode pug-tab-width)
- (python-mode . editorconfig--get-indentation-python-mode)
- (python-ts-mode . editorconfig--get-indentation-python-mode)
- (rjsx-mode js-indent-level sgml-basic-offset)
- (ruby-ts-mode ruby-indent-level)
- (rust-ts-mode rust-indent-offset
- rust-ts-mode-indent-offset)
- (scala-mode scala-indent:step)
- (scss-mode css-indent-offset)
- (sh-mode sh-basic-offset sh-indentation)
- (swift-mode swift-mode:basic-offset)
- (tcl-mode tcl-indent-level
- tcl-continued-indent-level)
- (templ-ts-mode go-ts-mode-indent-offset js-indent-level)
- (toml-ts-mode toml-ts-mode-indent-offset)
- (typescript-ts-base-mode typescript-ts-mode-indent-offset)
- (verilog-mode verilog-indent-level
- verilog-indent-level-behavioral
- verilog-indent-level-declaration
- verilog-indent-level-module
- verilog-cexp-indent
- verilog-case-indent)
- (web-mode . editorconfig--get-indentation-web-mode)
- (yaml-ts-mode yaml-indent-offset))
- "Alist of indentation setting methods by modes.
-
-This is a fallback used for those modes which don't set
-`editorconfig-indent-size-vars'.
-
-Each element looks like (MODE . FUNCTION) or (MODE . VARLIST).
-
-If FUNCTION is provided, it will be called with one argument (the indent size)
-when setting the indentation. It should return the list of settings that need
-to be applied, where each setting has the form (VARIABLE . VALUE).
-
-If VARLIST is provided, each element of VARLIST should be the name of
-a variable that we should set to the indent size.
-
-NOTE: Only the **buffer local** value of VARIABLE will be set."
- :type '(alist :key-type symbol :value-type sexp)
- :risky t)
-
-(defcustom editorconfig-exclude-modes ()
- "Modes in which `editorconfig-mode-apply' will not run."
- :type '(repeat (symbol :tag "Major Mode")))
-
-(defcustom editorconfig-exclude-regexps ()
- "List of regexp for buffer filenames `editorconfig-mode-apply' will not run.
-
-When variable `buffer-file-name' matches any of the regexps, then
-`editorconfig-mode-apply' will not do its work."
- :type '(repeat string))
-(with-eval-after-load 'recentf
- (add-to-list 'editorconfig-exclude-regexps
- (rx-to-string '(seq string-start
- (eval (file-truename (expand-file-name recentf-save-file))))
- t)))
-
-(defcustom editorconfig-trim-whitespaces-mode
- (when (fboundp 'delete-trailing-whitespace-mode)
- #'delete-trailing-whitespace-mode)
- "Buffer local minor-mode to use to trim trailing whitespaces.
-
-If set, enable that mode when `trim_trailing_whitespace` is set to true.
-Otherwise, use `delete-trailing-whitespace'."
- :type 'function)
-
-(defvar-local editorconfig-properties-hash nil
- "Hash object of EditorConfig properties that was enabled for current buffer.")
-(put 'editorconfig-properties-hash
- 'permanent-local
- t)
-
-(defvar editorconfig-lisp-use-default-indent nil
- "Selectively ignore the value of indent_size for Lisp files.
-Prevents `lisp-indent-offset' from being set selectively.
-
-nil - `lisp-indent-offset' is always set normally.
-t - `lisp-indent-offset' is never set normally
- (always use default indent for lisps).
-number - `lisp-indent-offset' is not set only if indent_size is
- equal to this number. For example, if this is set to 2,
- `lisp-indent-offset' will not be set only if indent_size is 2.")
-
-(defcustom editorconfig-override-file-local-variables t
- "Non-nil means editorconfig will override file local variable values."
- :type 'boolean)
-
-(defcustom editorconfig-override-dir-local-variables t
- "Non-nil means editorconfig will override values defined in dir-locals.el ."
- :type 'boolean)
-
-(define-error 'editorconfig-error
- "Error thrown from editorconfig lib")
-
-(defun editorconfig-error (&rest args)
- "Signal an `editorconfig-error'.
-Make a message by passing ARGS to `format-message'."
- (signal 'editorconfig-error (list (apply #'format-message args))))
-
-(defun editorconfig--disabled-for-filename (filename)
- "Return non-nil when EditorConfig is disabled for FILENAME."
- (cl-assert (stringp filename))
- (cl-loop for regexp in editorconfig-exclude-regexps
- if (string-match regexp filename) return t
- finally return nil))
-
-(defun editorconfig--disabled-for-majormode (majormode)
- "Return non-nil when Editorconfig is disabled for MAJORMODE."
- (cl-assert majormode)
- (or (provided-mode-derived-p majormode 'special-mode)
- ;; Some special modes (like `archive-mode') are not derived from
- ;; `special-mode'
- (eq (get majormode 'mode-class) 'special)
- (memq majormode
- editorconfig-exclude-modes)))
-
-(defun editorconfig-string-integer-p (string)
- "Return non-nil if STRING represents integer."
- (and (stringp string)
- (string-match-p "\\`[0-9]+\\'" string)))
-
-(defun editorconfig--get-indentation-web-mode (size)
- `((web-mode-indent-style . 2)
- (web-mode-attr-indent-offset . ,size)
- (web-mode-attr-value-indent-offset . ,size)
- (web-mode-code-indent-offset . ,size)
- (web-mode-css-indent-offset . ,size)
- (web-mode-markup-indent-offset . ,size)
- (web-mode-sql-indent-offset . ,size)
- (web-mode-block-padding . ,size)
- (web-mode-script-padding . ,size)
- (web-mode-style-padding . ,size)))
-
-(defun editorconfig--get-indentation-python-mode (size)
- "Vars to set `python-mode' indent size to SIZE."
- `((python-indent-offset . ,size) ;For python.el
- (py-indent-offset . ,size))) ;For python-mode.el
-
-(defun editorconfig--get-indentation-latex-mode (size)
- "Vars to set `latex-mode' indent size to SIZE."
- `((tex-indent-basic . ,size)
- (tex-indent-item . ,size)
- (tex-indent-arg . ,(* 2 size))
- ;; For AUCTeX
- (TeX-brace-indent-level . ,size)
- (LaTeX-indent-level . ,size)
- (LaTeX-item-indent . ,(- size))))
-
-(defun editorconfig--get-indentation-nxml-mode (size)
- "Vars to set `nxml-mode' indent size to SIZE."
- `((nxml-child-indent . ,size)
- (nxml-attribute-indent . ,(* 2 size))))
-
-(defun editorconfig--get-indentation-lisp-mode (size)
- "Set indent size to SIZE for Lisp mode(s)."
- (when (cond ((null editorconfig-lisp-use-default-indent) t)
- ((eql t editorconfig-lisp-use-default-indent) nil)
- ((numberp editorconfig-lisp-use-default-indent)
- (not (eql size editorconfig-lisp-use-default-indent)))
- (t t))
- `((lisp-indent-offset . ,size))))
-
-(cl-defun editorconfig--should-set (symbol)
- "Determine if editorconfig should set SYMBOL."
- (display-warning '(editorconfig editorconfig--should-set)
- (format "symbol: %S"
- symbol)
- :debug)
- (when (and (not editorconfig-override-file-local-variables)
- (assq symbol file-local-variables-alist))
- (cl-return-from editorconfig--should-set
- nil))
-
- (when (and (not editorconfig-override-dir-local-variables)
- (assq symbol dir-local-variables-alist))
- (cl-return-from editorconfig--should-set
- nil))
-
- t)
-
-(defvar editorconfig-indent-size-vars
- #'editorconfig--default-indent-size-function
- "Rule to use to set a given `indent_size'.
-This should hold the list of variables that need to be set to SIZE
-to tell the indentation code of the current major mode to use a basic
-indentation step of size SIZE.
-It can also take the form of a function, in which case we call it with
-a single SIZE argument (an integer) and it should return a list
-of (VAR . VAL) pairs indicating the variables to set and the values to
-set them to.
-Major modes are expected to set this buffer-locally.")
-
-(defun editorconfig--default-indent-size-function (size)
- "Guess which variables to set to for the indentation step to have size SIZE.
-This relies on `editorconfig-indentation-alist' supplemented with a crude
-heuristic for those modes not found there."
- (let ((parents (if (fboundp 'derived-mode-all-parents) ;Emacs-30
- (derived-mode-all-parents major-mode)
- (let ((modes nil)
- (mode major-mode))
- (while mode
- (push mode modes)
- (setq mode (get mode 'derived-mode--parent)))
- (nreverse modes))))
- entry)
- (let ((parents parents))
- (while (and parents (not entry))
- (setq entry (assq (pop parents) editorconfig-indentation-alist))))
- (or
- (when entry
- (let ((rule (cdr entry)))
- ;; Filter out settings of unknown vars.
- (delq nil
- (mapcar
- (lambda (elem)
- (let ((v (car elem)))
- (cond
- ((not (symbolp v))
- (message "Unsupported element in `editorconfig-indentation-alist': %S" elem))
- ((boundp v) elem))))
- (if (functionp rule)
- (let ((result (funcall rule size)))
- (if (and (consp (car-safe result))
- (boundp (caar result)))
- result
- (message "Invalid return value for: %S"
- rule)
- nil))
- (mapcar
- (lambda (elem)
- (cond
- ((symbolp elem) `(,elem . ,size))
- ((consp elem)
- (message "Old-style entry in editorconfig-indentation-alist: %S" elem)
- `(,(car elem)
- . ,(let ((spec (cdr elem)))
- (cond ((functionp spec) (funcall spec size))
- ((integerp spec) (* spec size))
- (t spec)))))))
- rule))))))
- ;; Fallback, let's try and guess.
- (let ((suffixes '("-indent-level" "-basic-offset" "-indent-offset"))
- (guess ()))
- (while (and parents (not guess))
- (let* ((mode (pop parents))
- (modename (symbol-name mode))
- (name (substring modename 0
- (string-match "-mode\\'" modename))))
- (dolist (suffix suffixes)
- (let ((sym (intern-soft (concat name suffix))))
- (when (and sym (boundp sym))
- (setq guess sym))))))
- (when guess `((,guess . ,size))))
- (and (local-variable-p 'smie-rules-function)
- `((smie-indent-basic . ,size))))))
-
-(defun editorconfig--get-indentation (style &optional size tab_width)
- "Get indentation vars according to STYLE, SIZE, and TAB_WIDTH."
- (if tab_width (setq tab_width (string-to-number tab_width)))
-
- (setq size
- (cond ((editorconfig-string-integer-p size)
- (string-to-number size))
- ((equal size "tab")
- (or tab_width tab-width))
- (t
- nil)))
-
- `(,@(cond (tab_width `((tab-width . ,tab_width)))
- ((numberp size) `((tab-width . ,size))))
-
- ,@(pcase style
- ("space" `((indent-tabs-mode . nil)))
- ("tab" `((indent-tabs-mode . t))))
-
- ,@(when (and size (featurep 'evil))
- `((evil-shift-width . ,size)))
-
- ,@(cond
- ((null size) nil)
- ((functionp editorconfig-indent-size-vars)
- (funcall editorconfig-indent-size-vars size))
- (t (mapcar (lambda (v) `(,v . ,size))
- editorconfig-indent-size-vars)))))
-
-
-(defun editorconfig-set-indentation (style &optional size tab_width)
- "Set indentation type from STYLE, SIZE and TAB_WIDTH."
- (dolist (setting (editorconfig--get-indentation style size tab_width))
- (when (editorconfig--should-set (car setting))
- (set (make-local-variable (car setting)) (cdr setting)))))
-
-(defvar-local editorconfig--apply-coding-system-currently nil
- "Used internally.")
-(put 'editorconfig--apply-coding-system-currently
- 'permanent-local
- t)
-
-(defun editorconfig-merge-coding-systems (end-of-line charset)
- "Return merged coding system symbol of END-OF-LINE and CHARSET."
- (let ((eol (cond
- ((equal end-of-line "lf") 'undecided-unix)
- ((equal end-of-line "cr") 'undecided-mac)
- ((equal end-of-line "crlf") 'undecided-dos)))
- (cs (cond
- ((equal charset "latin1") 'iso-latin-1)
- ((equal charset "utf-8") 'utf-8)
- ((equal charset "utf-8-bom") 'utf-8-with-signature)
- ((equal charset "utf-16be") 'utf-16be-with-signature)
- ((equal charset "utf-16le") 'utf-16le-with-signature))))
- (if (and eol cs)
- (merge-coding-systems cs eol)
- (or eol cs))))
-
-(cl-defun editorconfig-set-coding-system-revert (end-of-line charset)
- "Set buffer coding system by END-OF-LINE and CHARSET.
-
-This function will revert buffer when the coding-system has been changed."
- ;; `editorconfig--advice-find-file-noselect' does not use this function
- (let ((coding-system (editorconfig-merge-coding-systems end-of-line
- charset)))
- (display-warning '(editorconfig editorconfig-set-coding-system-revert)
- (format "editorconfig-set-coding-system-revert: buffer-file-name: %S | buffer-file-coding-system: %S | coding-system: %S | apply-currently: %S"
- buffer-file-name
- buffer-file-coding-system
- coding-system
- editorconfig--apply-coding-system-currently)
- :debug)
- (when (memq coding-system '(nil undecided))
- (cl-return-from editorconfig-set-coding-system-revert))
- (when (and buffer-file-coding-system
- (memq buffer-file-coding-system
- (coding-system-aliases (merge-coding-systems coding-system
- buffer-file-coding-system))))
- (cl-return-from editorconfig-set-coding-system-revert))
- (unless (file-readable-p buffer-file-name)
- (set-buffer-file-coding-system coding-system)
- (cl-return-from editorconfig-set-coding-system-revert))
- (unless (memq coding-system
- (coding-system-aliases editorconfig--apply-coding-system-currently))
- ;; Revert functions might call `editorconfig-apply' again
- ;; FIXME: I suspect `editorconfig--apply-coding-system-currently'
- ;; gymnastics is not needed now that we hook into `find-auto-coding'.
- (unwind-protect
- (progn
- (setq editorconfig--apply-coding-system-currently coding-system)
- ;; Revert without query if buffer is not modified
- (let ((revert-without-query '(".")))
- (revert-buffer-with-coding-system coding-system)))
- (setq editorconfig--apply-coding-system-currently nil)))))
-
-(defun editorconfig--delete-final-newline ()
- "Ensure the buffer does not end with a newline.
-Does nothing if the buffer is read-only."
- (unless buffer-read-only
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-max))
- (while (looking-at-p "^$")
- (delete-char -1))))))
-
-(defun editorconfig-set-trailing-nl (final-newline)
- "Set up requiring final newline by FINAL-NEWLINE.
-
-This function will set `require-final-newline' and `mode-require-final-newline'
-to non-nil when FINAL-NEWLINE is true."
- (pcase final-newline
- ("true"
- ;; keep prefs around how/when the nl is added, if set - otherwise add on save
- (setq-local require-final-newline (or require-final-newline t))
- (setq-local mode-require-final-newline (or mode-require-final-newline t))
- (remove-hook 'before-save-hook
- #'editorconfig--delete-final-newline t))
-
- ("false"
- (setq-local require-final-newline nil)
- (setq-local mode-require-final-newline nil)
- (add-hook 'before-save-hook
- #'editorconfig--delete-final-newline nil t))))
-
-(defun editorconfig--delete-trailing-whitespace ()
- "Call `delete-trailing-whitespace' unless the buffer is read-only."
- (unless buffer-read-only (delete-trailing-whitespace)))
-
-(defun editorconfig-set-trailing-ws (trim-trailing-ws)
- (pcase trim-trailing-ws
- ("true"
- (if editorconfig-trim-whitespaces-mode
- (funcall editorconfig-trim-whitespaces-mode 1)
- (add-hook 'before-save-hook
- #'editorconfig--delete-trailing-whitespace nil t)))
- ("false"
- (when editorconfig-trim-whitespaces-mode
- (funcall editorconfig-trim-whitespaces-mode 0))
- (remove-hook 'before-save-hook
- #'editorconfig--delete-trailing-whitespace t))))
-
-
-(defun editorconfig-set-line-length (length)
- "Set the max line length (`fill-column') to LENGTH."
- (when (and (editorconfig-string-integer-p length)
- (> (string-to-number length) 0))
- (setq fill-column (string-to-number length))))
-
-
-(defun editorconfig--execute-editorconfig-exec (filename)
- "Execute EditorConfig core with FILENAME and return output."
- (if filename
- (with-temp-buffer
- (let ((remote (file-remote-p filename))
- (remote-localname (file-remote-p filename
- 'localname)))
- (display-warning '(editorconfig editorconfig--execute-editorconfig-exec)
- (format "editorconfig--execute-editorconfig-exec: filename: %S | remote: %S | remote-localname: %S"
- filename
- remote
- remote-localname)
- :debug)
- (if remote
- (progn
- (cd (concat remote "/"))
- (setq filename remote-localname))
- (cd "/")))
- (display-warning '(editorconfig editorconfig--execute-editorconfig-exec)
- (format "editorconfig--execute-editorconfig-exec: default-directory: %S | filename: %S"
- default-directory
- filename
- )
- :debug)
- (if (eq 0
- (process-file editorconfig-exec-path nil t nil filename))
- (buffer-string)
- (editorconfig-error (buffer-string))))
- ""))
-
-(defun editorconfig--parse-properties (props-string)
- "Create properties hash table from PROPS-STRING."
- (let ((props-list (split-string props-string "\n"))
- (properties (make-hash-table)))
- (dolist (prop props-list properties)
- (let ((key-val (split-string prop " *= *")))
- (when (> (length key-val) 1)
- (let ((key (intern (car key-val)))
- (val (mapconcat #'identity (cdr key-val) "")))
- (puthash key val properties)))))))
-
-(defun editorconfig-get-properties-from-exec (filename)
- "Get EditorConfig properties of file FILENAME.
-
-This function uses value of `editorconfig-exec-path' to get properties."
- (if (executable-find editorconfig-exec-path)
- (editorconfig--parse-properties (editorconfig--execute-editorconfig-exec filename))
- (editorconfig-error "Unable to find editorconfig executable")))
-
-(defun editorconfig-get-properties (filename)
- "Get EditorConfig properties for file FILENAME.
-
-It calls `editorconfig-get-properties-from-exec' if
-`editorconfig-exec-path' is found, otherwise
-`editorconfig-core-get-properties-hash'."
- (if (and (executable-find editorconfig-exec-path)
- (not (file-remote-p filename)))
- (editorconfig-get-properties-from-exec filename)
- (require 'editorconfig-core)
- (editorconfig-core-get-properties-hash filename)))
-
-(defun editorconfig-call-get-properties-function (filename)
- "Call `editorconfig-get-properties-function' with FILENAME and return result.
-
-This function also removes `unset' properties and calls
-`editorconfig-hack-properties-functions'."
- (unless (functionp editorconfig-get-properties-function)
- (editorconfig-error "Invalid editorconfig-get-properties-function value"))
- (if (stringp filename)
- (setq filename (expand-file-name filename))
- (editorconfig-error "Invalid argument: %S" filename))
- (let ((props nil))
- (condition-case err
- (setq props (funcall editorconfig-get-properties-function
- filename))
- (error
- (editorconfig-error "Error from editorconfig-get-properties-function: %S"
- err)))
- (cl-loop for k being the hash-keys of props using (hash-values v)
- when (equal v "unset") do (remhash k props))
- props))
-
-(defun editorconfig-set-local-variables (props)
- "Set buffer variables according to EditorConfig PROPS."
- (editorconfig-set-indentation (gethash 'indent_style props)
- (gethash 'indent_size props)
- (gethash 'tab_width props))
- (editorconfig-set-trailing-nl (gethash 'insert_final_newline props))
- (editorconfig-set-trailing-ws (gethash 'trim_trailing_whitespace props))
- (editorconfig-set-line-length (gethash 'max_line_length props)))
-
-
-(defun editorconfig-major-mode-hook ()
- "Function to run when `major-mode' has been changed.
-
-This functions does not reload .editorconfig file, just sets local variables
-again. Changing major mode can reset these variables.
-
-This function also executes `editorconfig-after-apply-functions' functions."
- (display-warning '(editorconfig editorconfig-major-mode-hook)
- (format "editorconfig-major-mode-hook: editorconfig-mode: %S, major-mode: %S, -properties-hash: %S"
- (and (boundp 'editorconfig-mode)
- editorconfig-mode)
- major-mode
- editorconfig-properties-hash)
- :debug)
- (when (and (bound-and-true-p editorconfig-mode)
- editorconfig-properties-hash)
- (editorconfig-set-local-variables editorconfig-properties-hash)
- (condition-case err
- (run-hook-with-args 'editorconfig-after-apply-functions editorconfig-properties-hash)
- (error
- (display-warning '(editorconfig editorconfig-major-mode-hook)
- (format "Error while running `editorconfig-after-apply-functions': %S"
- err))))))
-
-;; This is a new var in Emacs≥30.
-;; We dyn-bind it in our `editorconfig--advice-find-auto-coding' advice
-;; to mimic the Emacs-30 behavior.
-(defvar auto-coding-file-name)
-
-(defun editorconfig--advice-find-auto-coding (filename &rest _args)
- "Consult `charset' setting of EditorConfig."
- (let ((cs (let ((auto-coding-file-name filename))
- (editorconfig--get-coding-system))))
- (when cs (cons cs 'EditorConfig))))
-
-(defun editorconfig--advice-find-file-noselect (f filename &rest args)
- "Get EditorConfig properties and apply them to buffer to be visited.
-
-This function should be added as an advice function to `find-file-noselect'.
-F is that function, and FILENAME and ARGS are arguments passed to F."
- (let ((props nil)
- (ret nil))
- (condition-case err
- (when (stringp filename)
- (setq props (editorconfig-call-get-properties-function filename)))
- (error
- (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
- (format "Failed to get properties, styles will not be applied: %S"
- err)
- :warning)))
-
- (setq ret (apply f filename args))
-
- (condition-case err
- (with-current-buffer ret
- (when props
-
- ;; NOTE: hack-properties-functions cannot affect coding-system value,
- ;; because it has to be set before initializing buffers.
- (condition-case err
- (run-hook-with-args 'editorconfig-hack-properties-functions props)
- (error
- (display-warning '(editorconfig editorconfig-hack-properties-functions)
- (format "Error while running editorconfig-hack-properties-functions, abort running hook: %S"
- err)
- :warning)))
- (setq editorconfig-properties-hash props)
- ;; When initializing buffer, `editorconfig-major-mode-hook'
- ;; will be called before setting `editorconfig-properties-hash', so
- ;; execute this explicitly here.
- (editorconfig-set-local-variables props)
-
- (condition-case err
- (run-hook-with-args 'editorconfig-after-apply-functions props)
- (error
- (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
- (format "Error while running `editorconfig-after-apply-functions': %S"
- err))))))
- (error
- (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
- (format "Error while setting variables from EditorConfig: %S" err))))
- ret))
-
-(defvar editorconfig--getting-coding-system nil)
-
-(defun editorconfig--get-coding-system (&optional _size)
- "Return the coding system to use according to EditorConfig.
-Meant to be used on `auto-coding-functions'."
- (when (and (stringp auto-coding-file-name)
- (file-name-absolute-p auto-coding-file-name)
- ;; Don't recurse infinitely.
- (not (member auto-coding-file-name
- editorconfig--getting-coding-system)))
- (let* ((editorconfig--getting-coding-system
- (cons auto-coding-file-name editorconfig--getting-coding-system))
- (props (editorconfig-call-get-properties-function
- auto-coding-file-name)))
- (editorconfig-merge-coding-systems (gethash 'end_of_line props)
- (gethash 'charset props)))))
-
-;;;###autoload
-(define-minor-mode editorconfig-mode
- "Toggle EditorConfig feature.
-
-To disable EditorConfig in some buffers, modify
-`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'."
- :global t
- :lighter editorconfig-mode-lighter
- (let ((modehooks '(prog-mode-hook
- text-mode-hook
- ;; Some modes call `kill-all-local-variables' in their init
- ;; code, which clears some values set by editorconfig.
- ;; For those modes, editorconfig-apply need to be called
- ;; explicitly through their hooks.
- rpm-spec-mode-hook)))
- (if editorconfig-mode
- (progn
- (advice-add 'find-file-noselect :around #'editorconfig--advice-find-file-noselect)
- (advice-add 'find-auto-coding :after-until
- #'editorconfig--advice-find-auto-coding)
- (dolist (hook modehooks)
- (add-hook hook
- #'editorconfig-major-mode-hook
- t)))
- (advice-remove 'find-file-noselect #'editorconfig--advice-find-file-noselect)
- (advice-remove 'find-auto-coding
- #'editorconfig--advice-find-auto-coding)
- (dolist (hook modehooks)
- (remove-hook hook #'editorconfig-major-mode-hook)))))
-
-
-;; (defconst editorconfig--version
-;; (eval-when-compile
-;; (require 'lisp-mnt)
-;; (declare-function lm-version "lisp-mnt" nil)
-;; (lm-version))
-;; "EditorConfig version.")
-
-;;;###autoload
-(defun editorconfig-version (&optional show-version)
- "Get EditorConfig version as string.
-
-If called interactively or if SHOW-VERSION is non-nil, show the
-version in the echo area and the messages buffer."
- (interactive (list t))
- (let ((version-full
- (if (fboundp 'package-get-version) ;Emacs≥27
- (package-get-version)
- (let* ((version
- (with-temp-buffer
- (require 'find-func)
- (declare-function find-library-name "find-func" (library))
- (insert-file-contents (find-library-name "editorconfig"))
- (require 'lisp-mnt)
- (declare-function lm-version "lisp-mnt" nil)
- (lm-version)))
- (pkg (and (eval-and-compile (require 'package nil t))
- (cadr (assq 'editorconfig
- package-alist))))
- (pkg-version (and pkg (package-version-join
- (package-desc-version pkg)))))
- (if (and pkg-version
- (not (string= version pkg-version)))
- (concat version "-" pkg-version)
- version)))))
- (when show-version
- (message "EditorConfig Emacs v%s" version-full))
- version-full))
-
-(provide 'editorconfig)
-;;; editorconfig.el ends here
+++ /dev/null
-This is editorconfig.info, produced by makeinfo version 6.8 from
-editorconfig.texi.
-
-INFO-DIR-SECTION Emacs
-START-INFO-DIR-ENTRY
-* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
-END-INFO-DIR-ENTRY
-
-\1f
-File: editorconfig.info, Node: Top, Next: Getting Started, Up: (dir)
-
-1 EditorConfig Emacs Plugin
-***************************
-
-This is an EditorConfig (https://editorconfig.org) plugin for Emacs
-(https://www.gnu.org/software/emacs/).
-
-* Menu:
-
-* Getting Started::
-* Supported properties::
-* Customize::
-* Troubleshooting::
-* Submitting Bugs and Feature Requests::
-* License::
-
-\1f
-File: editorconfig.info, Node: Getting Started, Next: Supported properties, Prev: Top, Up: Top
-
-1.1 Getting Started
-===================
-
-* Menu:
-
-* packageel::
-* use-package::
-* Manual installation::
-
-\1f
-File: editorconfig.info, Node: packageel, Next: use-package, Up: Getting Started
-
-1.1.1 package.el
-----------------
-
-This package is available from MELPA (https://melpa.org/#/editorconfig),
-MELPA Stable (https://stable.melpa.org/#/editorconfig) and NonGNU ELPA
-(http://elpa.nongnu.org/nongnu/editorconfig.html). Install from these
-repositories and enable global minor-mode 'editorconfig-mode':
-
-(editorconfig-mode 1)
-
- Normally, enabling 'editorconfig-mode' should be enough for this
-plugin to work: all other configurations are optional. This mode sets
-up hooks so that EditorConfig properties will be loaded and applied to
-the new buffers automatically when visiting files.
-
-\1f
-File: editorconfig.info, Node: use-package, Next: Manual installation, Prev: packageel, Up: Getting Started
-
-1.1.2 use-package
------------------
-
-If you use *use-package* (https://www.emacswiki.org/emacs/UsePackage),
-add the following to your 'init.el' file:
-
-(use-package editorconfig
- :ensure t
- :config
- (editorconfig-mode 1))
-
-\1f
-File: editorconfig.info, Node: Manual installation, Prev: use-package, Up: Getting Started
-
-1.1.3 Manual installation
--------------------------
-
-Copy all '.el' files in this repository to '~/.emacs.d/lisp' and add the
-following:
-
-(add-to-list 'load-path "~/.emacs.d/lisp")
-(require 'editorconfig)
-(editorconfig-mode 1)
-
-\1f
-File: editorconfig.info, Node: Supported properties, Next: Customize, Prev: Getting Started, Up: Top
-
-1.2 Supported properties
-========================
-
-Current Emacs plugin coverage for EditorConfig's properties
-(https://editorconfig.org/#supported-properties):
-
- * 'indent_style'
- * 'indent_size'
- * 'tab_width'
- * 'end_of_line'
- * 'charset'
- * 'trim_trailing_whitespace'
- * 'insert_final_newline = true' is supported
- * 'insert_final_newline = false' is not enforced (as in trailing
- newlines actually being removed automagically), we just
- buffer-locally override any preferences that would auto-add them to
- files '.editorconfig' marks as trailing-newline-free
- * 'max_line_length'
- * 'file_type_ext' (Experimental) (See below)
- * 'file_type_emacs' (Experimental) (See below)
- * 'root' (only used by EditorConfig core)
-
- Not yet covered properties marked with over-strike - pull requests
-implementing missing features warmly welcomed! Typically, you will want
-to tie these to native functionality, or the configuration of existing
-packages handling the feature.
-
- As several packages have their own handling of, say, indentation, we
-might not yet cover some mode you use, but we try to add the ones that
-show up on our radar.
-
-* Menu:
-
-* File Type file_type_ext file_type_emacs::
-
-\1f
-File: editorconfig.info, Node: File Type file_type_ext file_type_emacs, Up: Supported properties
-
-1.2.1 File Type (file_type_ext, file_type_emacs)
-------------------------------------------------
-
-File-type feature is currently disabled, because this package is now
-undergoing big internal refactoring. For those who want this
-functionality, please consider using editorconfig-custom-majormode
-(https://github.com/10sr/editorconfig-custom-majormode-el).
-
-\1f
-File: editorconfig.info, Node: Customize, Next: Troubleshooting, Prev: Supported properties, Up: Top
-
-1.3 Customize
-=============
-
-'editorconfig-emacs' provides some customize variables.
-
- Here are some of these variables: for the full list of available
-variables, type M-x customize-group [RET] editorconfig [RET].
-
-* Menu:
-
-* editorconfig-trim-whitespaces-mode::
-* editorconfig-after-apply-functions::
-* editorconfig-hack-properties-functions::
-
-\1f
-File: editorconfig.info, Node: editorconfig-trim-whitespaces-mode, Next: editorconfig-after-apply-functions, Up: Customize
-
-1.3.1 'editorconfig-trim-whitespaces-mode'
-------------------------------------------
-
-Buffer local minor-mode to use to trim trailing whitespaces.
-
- If set, editorconfig will enable/disable this mode in accord with
-'trim_trailing_whitespace' property in '.editorconfig'. Otherwise, use
-Emacs built-in 'delete-trailing-whitespace' function.
-
- One possible value is 'ws-butler-mode'
-(https://github.com/lewang/ws-butler), with which only lines touched get
-trimmed. To use it, add following to your init.el:
-
-(setq editorconfig-trim-whitespaces-mode
- 'ws-butler-mode)
-
-\1f
-File: editorconfig.info, Node: editorconfig-after-apply-functions, Next: editorconfig-hack-properties-functions, Prev: editorconfig-trim-whitespaces-mode, Up: Customize
-
-1.3.2 'editorconfig-after-apply-functions'
-------------------------------------------
-
-(Formerly 'editorconfig-custom-hooks')
-
- A list of functions which will be called after loading common
-EditorConfig settings, when you can set some custom variables.
-
- For example, 'web-mode' has several variables for indentation offset
-size and EditorConfig sets them at once by 'indent_size'. You can stop
-indenting only blocks of 'web-mode' by adding following to your init.el:
-
-(add-hook 'editorconfig-after-apply-functions
- (lambda (props) (setq web-mode-block-padding 0)))
-
-\1f
-File: editorconfig.info, Node: editorconfig-hack-properties-functions, Prev: editorconfig-after-apply-functions, Up: Customize
-
-1.3.3 'editorconfig-hack-properties-functions'
-----------------------------------------------
-
-A list of functions to alter property values before applying them.
-
- These functions will be run after loading ".editorconfig" files and
-before applying them to current buffer, so that you can alter some
-properties from ".editorconfig" before they take effect.
-
- For example, Makefile files always use tab characters for
-indentation: you can overwrite "indent_style" property when current
-'major-mode' is 'makefile-mode':
-
-(add-hook 'editorconfig-hack-properties-functions
- '(lambda (props)
- (when (derived-mode-p 'makefile-mode)
- (puthash 'indent_style "tab" props))))
-
-\1f
-File: editorconfig.info, Node: Troubleshooting, Next: Submitting Bugs and Feature Requests, Prev: Customize, Up: Top
-
-1.4 Troubleshooting
-===================
-
-Enabling 'editorconfig-mode' should be enough for normal cases.
-
- When EditorConfig properties are not effective for unknown reason, we
-recommend first trying 'M-x editorconfig-display-current-properties'.
-
- This command will open a new buffer and display the EditorConfig
-properties loaded for current buffer. You can check if EditorConfig
-properties were not read for buffers at all, or they were loaded but did
-not take effect for some other reasons.
-
-* Menu:
-
-* Indentation for new major-modes::
-* Not work at all for FOO-mode!::
-
-\1f
-File: editorconfig.info, Node: Indentation for new major-modes, Next: Not work at all for FOO-mode!, Up: Troubleshooting
-
-1.4.1 Indentation for new major-modes
--------------------------------------
-
-Because most Emacs major-modes have their own indentation settings, this
-plugin requires explicit support for each major-mode for 'indent_size'
-property.
-
- By default this plugin ships with settings for many major-modes, but,
-sorry to say, it cannot be perfect. Especially it is difficult to
-support brand-new major-modes. Please feel free to submit issue or
-pull-request for such major-mode!
-
- Supported major-modes and their indentation configs are defined in
-the variable 'editorconfig-indentation-alist'.
-
-\1f
-File: editorconfig.info, Node: Not work at all for FOO-mode!, Prev: Indentation for new major-modes, Up: Troubleshooting
-
-1.4.2 Not work at all for FOO-mode!
------------------------------------
-
-Most cases properties are loaded just after visiting files when
-'editorconfig-mode' is enabled. But it is known that there are
-major-modes that this mechanism does not work for and require explicit
-call of 'editorconfig-apply'.
-
- Typically it will occur when the major-mode is not defined using
-'define-derived-mode' ('rpm-spec-mode' is an example for this). Please
-feel free to submit issues if you find such modes!
-
-\1f
-File: editorconfig.info, Node: Submitting Bugs and Feature Requests, Next: License, Prev: Troubleshooting, Up: Top
-
-1.5 Submitting Bugs and Feature Requests
-========================================
-
-Bugs, feature requests, and other issues should be submitted to the
-issue tracker: https://github.com/editorconfig/editorconfig-emacs/issues
-
-* Menu:
-
-* Development::
-
-\1f
-File: editorconfig.info, Node: Development, Up: Submitting Bugs and Feature Requests
-
-1.5.1 Development
------------------
-
-Make and CMake (https://cmake.org) must be installed to run the tests
-locally:
-
-$ make check
-
- To start a new Emacs process with current '*.el' and without loading
-user init file, run:
-
-$ make sandbox
-
-\1f
-File: editorconfig.info, Node: License, Prev: Submitting Bugs and Feature Requests, Up: Top
-
-1.6 License
-===========
-
-EditorConfig Emacs Plugin is free software: you can redistribute it
-and/or modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation, either version 3 of the
-License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-Public License for more details.
-
- You should have received a copy of the GNU General Public License
-along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-
-\1f
-Tag Table:
-Node: Top\7f208
-Ref: #editorconfig-emacs-plugin\7f340
-Node: Getting Started\7f590
-Ref: #getting-started\7f733
-Node: packageel\7f797
-Ref: #package.el\7f919
-Node: use-package\7f1483
-Ref: #use-package\7f1635
-Node: Manual installation\7f1823
-Ref: #manual-installation\7f1973
-Node: Supported properties\7f2148
-Ref: #supported-properties\7f2307
-Node: File Type file_type_ext file_type_emacs\7f3481
-Ref: #file-type-file_type_ext-file_type_emacs\7f3682
-Node: Customize\7f3941
-Ref: #customize\7f4078
-Node: editorconfig-trim-whitespaces-mode\7f4397
-Ref: #editorconfig-trim-whitespaces-mode\7f4613
-Node: editorconfig-after-apply-functions\7f5104
-Ref: #editorconfig-after-apply-functions\7f5367
-Node: editorconfig-hack-properties-functions\7f5853
-Ref: #editorconfig-hack-properties-functions\7f6081
-Node: Troubleshooting\7f6691
-Ref: #troubleshooting\7f6856
-Node: Indentation for new major-modes\7f7396
-Ref: #indentation-for-new-major-modes\7f7600
-Node: Not work at all for FOO-mode!\7f8116
-Ref: #not-work-at-all-for-foo-mode\7f8316
-Node: Submitting Bugs and Feature Requests\7f8738
-Ref: #submitting-bugs-and-feature-requests\7f8943
-Node: Development\7f9111
-Ref: #development\7f9238
-Node: License\7f9442
-Ref: #license\7f9565
-\1f
-End Tag Table
-
-\1f
-Local Variables:
-coding: utf-8
-End:
--- /dev/null
+EditorConfig helps developers define and maintain consistent
+coding styles between different editors and IDEs.
+
+The EditorConfig project consists of a file format for defining
+coding styles and a collection of text editor plugins that enable
+editors to read the file format and adhere to defined styles.
+EditorConfig files are easily readable and they work nicely with
+version control systems.
--- /dev/null
+This is the file .../info/dir, which contains the
+topmost node of the Info hierarchy, called (dir)Top.
+The first time you invoke Info you start off looking at this node.
+\1f
+File: dir, Node: Top This is the top of the INFO tree
+
+ This (the Directory node) gives a menu of major topics.
+ Typing "q" exits, "H" lists all Info commands, "d" returns here,
+ "h" gives a primer for first-timers,
+ "mEmacs<Return>" visits the Emacs manual, etc.
+
+ In Emacs, you can click mouse button 2 on a menu item or cross reference
+ to select it.
+
+* Menu:
+
+Emacs
+* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
--- /dev/null
+;;; editorconfig-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*-
+;; Generated by the `loaddefs-generate' function.
+
+;; This file is part of GNU Emacs.
+
+;;; Code:
+
+(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path)))
+
+
+\f
+;;; Generated autoloads from editorconfig.el
+
+(defvar editorconfig-mode nil
+"Non-nil if Editorconfig mode is enabled.
+See the `editorconfig-mode' command
+for a description of this minor mode.
+Setting this variable directly does not take effect;
+either customize it (see the info node `Easy Customization')
+or call the function `editorconfig-mode'.")
+(custom-autoload 'editorconfig-mode "editorconfig" nil)
+(autoload 'editorconfig-mode "editorconfig"
+"Toggle EditorConfig feature.
+
+To disable EditorConfig in some buffers, modify
+`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'.
+
+This is a global minor mode. If called interactively, toggle the
+`Editorconfig mode' mode. If the prefix argument is positive, enable
+the mode, and if it is zero or negative, disable the mode.
+
+If called from Lisp, toggle the mode if ARG is `toggle'. Enable the
+mode if ARG is nil, omitted, or is a positive number. Disable the mode
+if ARG is a negative number.
+
+To check whether the minor mode is enabled in the current buffer,
+evaluate `(default-value \\='editorconfig-mode)'.
+
+The mode's hook is called both when the mode is enabled and when it is
+disabled.
+
+(fn &optional ARG)" t)
+(autoload 'editorconfig-version "editorconfig"
+"Get EditorConfig version as string.
+
+If called interactively or if SHOW-VERSION is non-nil, show the
+version in the echo area and the messages buffer.
+
+(fn &optional SHOW-VERSION)" t)
+(register-definition-prefixes "editorconfig" '("editorconfig-"))
+
+\f
+;;; Generated autoloads from editorconfig-conf-mode.el
+
+(autoload 'editorconfig-conf-mode "editorconfig-conf-mode"
+"Major mode for editing .editorconfig files.
+
+In addition to any hooks its parent mode `conf-unix-mode' might have
+run, this mode runs the hook `editorconfig-conf-mode-hook', as the
+final or penultimate step during initialization.
+
+\\{editorconfig-conf-mode-map}" t)
+(add-to-list 'auto-mode-alist '("\\.editorconfig\\'" . editorconfig-conf-mode))
+(register-definition-prefixes "editorconfig-conf-mode" '("editorconfig-conf-mode-"))
+
+\f
+;;; Generated autoloads from editorconfig-core.el
+
+(autoload 'editorconfig-core-get-nearest-editorconfig "editorconfig-core"
+"Return path to .editorconfig file that is closest to DIRECTORY.
+
+(fn DIRECTORY)")
+(register-definition-prefixes "editorconfig-core" '("editorconfig-core-"))
+
+\f
+;;; Generated autoloads from editorconfig-core-handle.el
+
+(register-definition-prefixes "editorconfig-core-handle" '("editorconfig-core-handle"))
+
+\f
+;;; Generated autoloads from editorconfig-fnmatch.el
+
+(register-definition-prefixes "editorconfig-fnmatch" '("editorconfig-fnmatch-"))
+
+\f
+;;; Generated autoloads from editorconfig-tools.el
+
+(autoload 'editorconfig-apply "editorconfig-tools"
+"Get and apply EditorConfig properties to current buffer.
+
+This function does not respect the values of `editorconfig-exclude-modes' and
+`editorconfig-exclude-regexps' and always applies available properties.
+Use `editorconfig-mode-apply' instead to make use of these variables." t)
+(autoload 'editorconfig-mode-apply "editorconfig-tools"
+"Get and apply EditorConfig properties to current buffer.
+
+This function does nothing when the major mode is listed in
+`editorconfig-exclude-modes', or variable `buffer-file-name' matches
+any of regexps in `editorconfig-exclude-regexps'." t)
+(autoload 'editorconfig-find-current-editorconfig "editorconfig-tools"
+"Find the closest .editorconfig file for current file." t)
+(autoload 'editorconfig-display-current-properties "editorconfig-tools"
+"Display EditorConfig properties extracted for current buffer." t)
+(defalias 'describe-editorconfig-properties #'editorconfig-display-current-properties)
+(autoload 'editorconfig-format-buffer "editorconfig-tools"
+"Format buffer according to .editorconfig indent_style and indent_width." t)
+\f
+;;; End of scraped data
+
+(provide 'editorconfig-autoloads)
+
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; no-native-compile: t
+;; coding: utf-8-emacs-unix
+;; End:
+
+;;; editorconfig-autoloads.el ends here
--- /dev/null
+;;; editorconfig-conf-mode.el --- Major mode for editing .editorconfig files -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2024 EditorConfig Team
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
+;; or the CONTRIBUTORS file for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU General Public License along with
+;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Major mode for editing .editorconfig files.
+
+;;; Code:
+
+(require 'conf-mode)
+
+(defvar editorconfig-conf-mode-syntax-table
+ (let ((table (make-syntax-table conf-unix-mode-syntax-table)))
+ (modify-syntax-entry ?\; "<" table)
+ table)
+ "Syntax table in use in `editorconfig-conf-mode' buffers.")
+
+(defvar editorconfig-conf-mode-abbrev-table nil
+ "Abbrev table in use in `editorconfig-conf-mode' buffers.")
+(define-abbrev-table 'editorconfig-conf-mode-abbrev-table ())
+
+;;;###autoload
+(define-derived-mode editorconfig-conf-mode conf-unix-mode "Conf[EditorConfig]"
+ "Major mode for editing .editorconfig files."
+ (set-variable 'indent-line-function 'indent-relative)
+ (let ((key-property-list
+ '("charset"
+ "end_of_line"
+ "file_type_emacs"
+ "file_type_ext"
+ "indent_size"
+ "indent_style"
+ "insert_final_newline"
+ "max_line_length"
+ "root"
+ "tab_width"
+ "trim_trailing_whitespace"))
+ (key-value-list
+ '("unset"
+ "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))))
+
+ ;; Highlight all key values
+ (dolist (key-value key-value-list)
+ (push `(,(format "[=:][ \t]*\\(%s\\)\\([ \t]\\|$\\)" key-value)
+ 1 font-lock-constant-face)
+ font-lock-value))
+ ;; Highlight all key properties
+ (dolist (key-property key-property-list)
+ (push `(,(format "^[ \t]*\\(%s\\)[ \t]*[=:]" key-property)
+ 1 font-lock-builtin-face)
+ font-lock-value))
+
+ (conf-mode-initialize "#" font-lock-value)))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.editorconfig\\'" . editorconfig-conf-mode))
+
+(provide 'editorconfig-conf-mode)
+;;; editorconfig-conf-mode.el ends here
--- /dev/null
+;;; editorconfig-core-handle.el --- Handle Class for EditorConfig File -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+;; Package: editorconfig
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors or
+;; https://github.com/editorconfig/editorconfig-emacs/blob/master/CONTRIBUTORS
+;; for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+;; See the GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Handle structures for EditorConfig config file. This library is used
+;; internally from editorconfig-core.el .
+
+;;; Code:
+
+(require 'cl-lib)
+(when (eval-when-compile (version< emacs-version "28.1"))
+ ;; For `string-trim'
+ (require 'subr-x))
+
+(require 'editorconfig-fnmatch)
+
+(defvar editorconfig-core-handle--cache-hash
+ (make-hash-table :test 'equal)
+ "Hash of EditorConfig filename and its `editorconfig-core-handle' instance.")
+
+(cl-defstruct editorconfig-core-handle-section
+ "Structure representing one section in a .editorconfig file.
+
+Slots:
+
+`name'
+ String of section name (glob string).
+
+`props'
+ Alist of properties: (KEY . VALUE)."
+ (name nil)
+ (props nil))
+
+(defun editorconfig-core-handle-section-get-properties (section file)
+ "Return properties alist when SECTION name match FILE.
+
+FILE should be a relative file name, relative to the directory where
+the `.editorconfig' file which has SECTION lives.
+If not match, return nil."
+ (when (editorconfig-core-handle--fnmatch-p
+ file (editorconfig-core-handle-section-name section))
+ (editorconfig-core-handle-section-props section)))
+
+(cl-defstruct editorconfig-core-handle
+ "Structure representing an .editorconfig file.
+
+Slots:
+`top-props'
+ Alist of top properties like ((\"root\" . \"true\"))
+
+`sections'
+ List of `editorconfig-core-handle-section' structure objects.
+
+`mtime'
+ Last modified time of .editorconfig file.
+
+`path'
+ Absolute path to .editorconfig file."
+ (top-props nil)
+ (sections nil)
+ (mtime nil)
+ (path nil))
+
+
+(defun editorconfig-core-handle (conf)
+ "Return EditorConfig handle for CONF, which should be a file path.
+
+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))))
+ (if (and cached
+ (equal (editorconfig-core-handle-mtime cached) mtime))
+ cached
+ (let ((parsed (editorconfig-core-handle--parse-file conf)))
+ (puthash conf parsed editorconfig-core-handle--cache-hash))))))
+
+(defun editorconfig-core-handle-root-p (handle)
+ "Return non-nil if HANDLE represent root EditorConfig file.
+
+If HANDLE is nil return nil."
+ (when handle
+ (string-equal "true"
+ (downcase (or (cdr (assoc "root"
+ (editorconfig-core-handle-top-props handle)))
+ "")))))
+
+(defun editorconfig-core-handle-get-properties (handle file)
+ "Return list of alist of properties from HANDLE for FILE.
+The list returned will be ordered by the lines they appear.
+
+If HANDLE is nil return nil."
+ (declare (obsolete editorconfig-core-handle-get-properties-hash "0.8.0"))
+ (when handle
+ (let* ((dir (file-name-directory (editorconfig-core-handle-path handle)))
+ (file (file-relative-name file dir)))
+ (cl-loop for section in (editorconfig-core-handle-sections handle)
+ for props = (editorconfig-core-handle-section-get-properties
+ section file)
+ when props collect (copy-alist props)))))
+
+
+(defun editorconfig-core-handle-get-properties-hash (handle file)
+ "Return hash of properties from HANDLE for FILE.
+
+If HANDLE is nil return nil."
+ (when handle
+ (let* ((hash (make-hash-table))
+ (dir (file-name-directory (editorconfig-core-handle-path handle)))
+ (file (file-relative-name file dir)))
+ (dolist (section (editorconfig-core-handle-sections handle))
+ (cl-loop for (key . value) in (editorconfig-core-handle-section-get-properties section file)
+ do (puthash (intern key) value hash)))
+ hash)))
+
+(defun editorconfig-core-handle--fnmatch-p (name pattern)
+ "Return non-nil if NAME match PATTERN.
+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)))
+ (editorconfig-fnmatch-p name pattern))
+ ;; The match is not "anchored" so it can be either in the current dir or
+ ;; in a subdir. Contrary to Zsh patterns, editorconfig's `**/foo' does
+ ;; not match `foo', so we need to split the problem into two matches.
+ (or (editorconfig-fnmatch-p name pattern)
+ (editorconfig-fnmatch-p name (concat "**/" pattern)))))
+
+(defun editorconfig-core-handle--parse-file (conf)
+ "Parse EditorConfig file CONF.
+
+This function returns a `editorconfig-core-handle'.
+If CONF is not found return nil."
+ (when (file-readable-p conf)
+ (with-temp-buffer
+ ;; NOTE: Use this instead of insert-file-contents-literally to enable
+ ;; code conversion
+ (insert-file-contents conf)
+ (goto-char (point-min))
+ (let ((sections ())
+ (top-props nil)
+
+ ;; nil when pattern not appeared yet, "" when pattern is empty ("[]")
+ (pattern nil)
+ ;; Alist of properties for current PATTERN
+ (props ()))
+ (while (not (eobp))
+ (skip-chars-forward " \t\f")
+ (cond
+ ((looking-at "\\(?:[#;].*\\)?$")
+ nil)
+
+ ;; Start of section
+ ((looking-at "\\[\\(.*\\)\\][ \t]*\\(?:[#;].*\\)?$")
+ (let ((newpattern (match-string 1)))
+ (when pattern
+ (push (make-editorconfig-core-handle-section
+ :name pattern
+ :props (nreverse props))
+ sections))
+ (setq props nil)
+ (setq pattern newpattern)))
+
+ ((looking-at "\\([^=: \n\t][^=:\n]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
+ (let ((key (downcase (string-trim (match-string 1))))
+ (value (match-string 2)))
+ (if pattern
+ (push `(,key . ,value)
+ props)
+ (push `(,key . ,value)
+ top-props))))
+
+ (t (error "Error while reading config file: %s:%d:\n %s\n"
+ conf (line-number-at-pos)
+ (buffer-substring-no-properties (line-beginning-position)
+ (line-end-position)))))
+ (forward-line 1))
+ (when pattern
+ (push (make-editorconfig-core-handle-section
+ :name pattern
+ :props (nreverse props))
+ sections))
+ (make-editorconfig-core-handle
+ :top-props (nreverse top-props)
+ :sections (nreverse sections)
+ :mtime (nth 5 (file-attributes conf))
+ :path conf)))))
+
+(provide 'editorconfig-core-handle)
+;;; editorconfig-core-handle.el ends here
--- /dev/null
+;;; editorconfig-core.el --- EditorConfig Core library in Emacs Lisp -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2024 EditorConfig Team
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
+;; or the CONTRIBUTORS file for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU General Public License along with
+;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library is one implementation of EditorConfig Core, which parses
+;; .editorconfig files and returns properties for given files.
+;; This can be used in place of, for example, editorconfig-core-c.
+
+
+;; Use from EditorConfig Emacs Plugin
+
+;; Emacs plugin (v0.5 or later) can utilize this implementation.
+;; By default, the plugin first search for any EditorConfig executable,
+;; and fallback to this library if not found.
+;; If you always want to use this library, add following lines to your init.el:
+
+;; (setq editorconfig-get-properties-function
+;; #'editorconfig-core-get-properties-hash)
+
+
+;; Functions
+
+;; editorconfig-core-get-properties (&optional file confname confversion)
+
+;; Get EditorConfig properties for FILE.
+
+;; If FILE is not given, use currently visiting file.
+;; Give CONFNAME for basename of config file other than .editorconfig.
+;; If need to specify config format version, give CONFVERSION.
+
+;; This functions returns alist of properties. Each element will look like
+;; (KEY . VALUE) .
+
+
+;; editorconfig-core-get-properties-hash (&optional file confname)
+
+;; Get EditorConfig properties for FILE.
+
+;; This function is almost same as `editorconfig-core-get-properties', but
+;; returns hash object instead.
+
+;;; Code:
+
+(require 'cl-lib)
+
+(require 'editorconfig-core-handle)
+
+(eval-when-compile
+ (require 'subr-x))
+
+
+(defun editorconfig-core--get-handles (dir confname &optional result)
+ "Get list of EditorConfig handlers for DIR from CONFNAME.
+
+In the resulting list, the handle for root config file comes first, and the
+nearest comes last.
+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))))
+ (if (or (string= parent dir)
+ (and handle (editorconfig-core-handle-root-p handle)))
+ (cl-remove-if-not #'identity (cons handle result))
+ (editorconfig-core--get-handles parent
+ confname
+ (cons handle result)))))
+
+;;;###autoload
+(defun editorconfig-core-get-nearest-editorconfig (directory)
+ "Return path to .editorconfig file that is closest to DIRECTORY."
+ (when-let* ((handle (car (last
+ (editorconfig-core--get-handles directory
+ ".editorconfig")))))
+ (editorconfig-core-handle-path handle)))
+
+(defun editorconfig-core--hash-merge (into update)
+ "Merge two hashes INTO and UPDATE.
+
+This is a destructive function, hash INTO will be modified.
+When the same key exists in both two hashes, values of UPDATE takes precedence."
+ (maphash (lambda (key value) (puthash key value into)) update)
+ into)
+
+(defun editorconfig-core-get-properties-hash (&optional file confname)
+ "Get EditorConfig properties for FILE.
+If FILE is not given, use currently visiting file.
+Give CONFNAME for basename of config file other than .editorconfig.
+If need to specify config format version, give CONFVERSION.
+
+This function is almost same as `editorconfig-core-get-properties', but returns
+hash object instead."
+ (setq file
+ (expand-file-name (or file
+ buffer-file-name
+ (error "FILE is not given and `buffer-file-name' is nil"))))
+ (setq confname (or confname ".editorconfig"))
+ (let ((result (make-hash-table)))
+ (dolist (handle (editorconfig-core--get-handles (file-name-directory file)
+ confname))
+ (editorconfig-core--hash-merge result
+ (editorconfig-core-handle-get-properties-hash handle
+ file)))
+
+ ;; Downcase known boolean values
+ ;; FIXME: Why not do that in `editorconfig-core-handle--parse-file'?
+ (dolist (key '( end_of_line indent_style indent_size insert_final_newline
+ trim_trailing_whitespace charset))
+ (when-let* ((val (gethash key result)))
+ (puthash key (downcase val) result)))
+
+ result))
+
+(provide 'editorconfig-core)
+;;; editorconfig-core.el ends here
--- /dev/null
+;;; editorconfig-fnmatch.el --- Glob pattern matching -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+;; Package: editorconfig
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors or
+;; https://github.com/editorconfig/editorconfig-emacs/blob/master/CONTRIBUTORS
+;; for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+;; See the GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; editorconfig-fnmatch.el provides a fnmatch implementation with a few
+;; extensions.
+;; The main usage of this library is glob pattern matching for EditorConfig, but
+;; it can also act solely.
+
+;; editorconfig-fnmatch-p (name pattern)
+
+;; Test whether NAME match PATTERN.
+
+;; PATTERN should be a shell glob pattern, and some zsh-like wildcard matchings
+;; can be used:
+
+;; * Matches any string of characters, except path separators (/)
+;; ** Matches any string of characters
+;; ? Matches any single character
+;; [name] Matches any single character in name
+;; [^name] Matches any single character not in name
+;; {s1,s2,s3} Matches any of the strings given (separated by commas)
+;; {min..max} Matches any number between min and max
+
+
+;; This library is a port from editorconfig-core-py library.
+;; https://github.com/editorconfig/editorconfig-core-py/blob/master/editorconfig/fnmatch.py
+
+;;; Code:
+
+(require 'cl-lib)
+
+(defconst editorconfig-fnmatch--cache-hashtable ;; Clear cache on file reload.
+ (make-hash-table :test 'equal)
+ "Cache of shell pattern and its translation.")
+
+(defconst editorconfig-fnmatch--left-brace-regexp
+ "\\(^\\|[^\\]\\){"
+ "Regular expression for left brace ({).")
+
+(defconst editorconfig-fnmatch--right-brace-regexp
+ "\\(^\\|[^\\]\\)}"
+ "Regular expression for right brace (}).")
+
+
+(defconst editorconfig-fnmatch--numeric-range-regexp
+ "\\([+-]?[0-9]+\\)\\.\\.\\([+-]?[0-9]+\\)"
+ "Regular expression for numeric range (like {-3..+3}).")
+
+(defun editorconfig-fnmatch--match-num (regexp string)
+ "Return how many times REGEXP is found in STRING."
+ (let ((num 0))
+ ;; 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))))
+ num))
+
+(defun editorconfig-fnmatch-p (string pattern)
+ "Test whether STRING match PATTERN.
+
+Matching ignores case if `case-fold-search' is non-nil.
+
+PATTERN should be a shell glob pattern, and some zsh-like wildcard matchings can
+be used:
+
+* Matches any string of characters, except path separators (/)
+** Matches any string of characters
+? Matches any single character
+[name] Matches any single character in name
+[^name] Matches any single character not in name
+{s1,s2,s3} Matches any of the strings given (separated by commas)
+{min..max} Matches any number between min and max"
+ (string-match (editorconfig-fnmatch-translate pattern)
+ string))
+
+;;(editorconfig-fnmatch-translate "{a,{-3..3}}.js")
+;;(editorconfig-fnmatch-p "1.js" "{a,{-3..3}}.js")
+
+(defun editorconfig-fnmatch-translate (pattern)
+ "Translate a shell PATTERN to a regular expression.
+
+Translation result will be cached, so same translation will not be done twice."
+ (let ((cached (gethash pattern
+ editorconfig-fnmatch--cache-hashtable)))
+ (or cached
+ (puthash pattern
+ (editorconfig-fnmatch--do-translate pattern)
+ editorconfig-fnmatch--cache-hashtable))))
+
+
+(defun editorconfig-fnmatch--do-translate (pattern &optional nested)
+ "Translate a shell PATTERN to a regular expression.
+
+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, in reverse order.
+ (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)))
+
+ 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)))
+ (progn
+ (push (regexp-quote (match-string 0 pattern)) result)
+ (setq index (match-end 0)
+ is-escaped nil))
+
+ (setq current-char (aref pattern index)
+ index (1+ index))
+
+ (push
+ (cl-case current-char
+ (?*
+ (setq pos index)
+ (if (and (< pos length)
+ (= (aref pattern pos) ?*))
+ (progn
+ (setq index (1+ index))
+ ".*")
+ "[^/]*"))
+
+ (?? "[^/]")
+
+ (?\[
+ (if in-brackets
+ "\\["
+ (if (= (aref pattern index) ?/)
+ ;; Slash after an half-open bracket
+ (progn
+ (setq index (+ index 1))
+ "\\[/")
+ (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
+ (let ((content (substring pattern index (1+ pos))))
+ (setq index (+ pos 2))
+ (concat "\\[" content "\\]"))
+ (setq in-brackets t)
+ (if (and (< index length)
+ (memq (aref pattern index)
+ '(?! ?^)))
+ (progn
+ (setq index (1+ index))
+ "[^")
+ "[")))))
+
+ (?\] (setq 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))
+ (setq index (1+ pos))
+ (if num-range
+ (let ((number-start (string-to-number
+ (match-string 1 pattern-sub)))
+ (number-end (string-to-number
+ (match-string 2 pattern-sub))))
+ (regexp-opt
+ (mapcar #'number-to-string
+ (cl-loop for i from number-start to number-end
+ collect i))))
+ (let ((inner (editorconfig-fnmatch--do-translate
+ pattern-sub t)))
+ (format "{%s}" inner))))
+ (if matching-braces
+ (progn
+ (setq brace-level (1+ brace-level))
+ "\\(?:")
+ "{")))
+
+ (?,
+ (if (and (> brace-level 0)
+ (not is-escaped))
+ "\\|" ","))
+
+ (?\}
+ (if (and (> brace-level 0)
+ (not is-escaped))
+ (progn
+ (setq brace-level (- brace-level 1))
+ "\\)")
+ "}"))
+
+ (?/
+ (if (and (<= (+ index 3) (length pattern))
+ (string= (substring pattern index (+ index 3)) "**/"))
+ (progn
+ (setq index (+ index 3))
+ "\\(?:/\\|/.*/\\)")
+ "/"))
+
+ (?\\ (when is-escaped "\\\\"))
+ (t (regexp-quote (char-to-string current-char))))
+ result)
+
+ (setq is-escaped (and (= current-char ?\\) (not is-escaped)))))
+ (unless nested
+ (setq result `("\\'" ,@result "\\`")))
+ (apply #'concat (reverse result))))
+
+(provide 'editorconfig-fnmatch)
+;;; editorconfig-fnmatch.el ends here
--- /dev/null
+;; -*- no-byte-compile: t; lexical-binding: nil -*-
+(define-package "editorconfig" "20260118.718"
+ "EditorConfig Emacs Plugin."
+ '((emacs "27.2"))
+ :url "https://github.com/editorconfig/editorconfig-emacs#readme"
+ :commit "1e9931d5f38a8d8cb8a92cf726d64696550bfc95"
+ :revdesc "1e9931d5f38a"
+ :keywords '("convenience" "editorconfig")
+ :authors '(("EditorConfig Team" . "editorconfigNOSPAMgooglegroups.com"))
+ :maintainers '(("EditorConfig Team" . "editorconfigNOSPAMgooglegroups.com")))
--- /dev/null
+;;; editorconfig-tools.el --- Editorconfig tools -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2024 EditorConfig Team
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
+;; or the CONTRIBUTORS file for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU General Public License along with
+;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Some utility commands for users, not used from editorconfig-mode.
+
+;;; Code:
+
+(require 'cl-lib)
+
+(eval-when-compile
+ (require 'subr-x))
+
+
+(require 'editorconfig)
+
+;;;###autoload
+(defun editorconfig-apply ()
+ "Get and apply EditorConfig properties to current buffer.
+
+This function does not respect the values of `editorconfig-exclude-modes' and
+`editorconfig-exclude-regexps' and always applies available properties.
+Use `editorconfig-mode-apply' instead to make use of these variables."
+ (interactive)
+ (when buffer-file-name
+ (condition-case err
+ (progn
+ (let ((props (editorconfig-call-get-properties-function buffer-file-name)))
+ (condition-case err
+ (run-hook-with-args 'editorconfig-hack-properties-functions props)
+ (error
+ (display-warning '(editorconfig editorconfig-hack-properties-functions)
+ (format "Error while running editorconfig-hack-properties-functions, abort running hook: %S"
+ err)
+ :warning)))
+ (setq editorconfig-properties-hash props)
+ (editorconfig-set-local-variables props)
+ (editorconfig-set-coding-system-revert
+ (gethash 'end_of_line props)
+ (gethash 'charset props))
+ (condition-case err
+ (run-hook-with-args 'editorconfig-after-apply-functions props)
+ (error
+ (display-warning '(editorconfig editorconfig-after-apply-functions)
+ (format "Error while running editorconfig-after-apply-functions, abort running hook: %S"
+ err)
+ :warning)))))
+ (error
+ (display-warning '(editorconfig editorconfig-apply)
+ (format "Error in editorconfig-apply, styles will not be applied: %S" err)
+ :error)))))
+
+;;;###autoload
+(defun editorconfig-mode-apply ()
+ "Get and apply EditorConfig properties to current buffer.
+
+This function does nothing when the major mode is listed in
+`editorconfig-exclude-modes', or variable `buffer-file-name' matches
+any of regexps in `editorconfig-exclude-regexps'."
+ (interactive)
+ (when (and major-mode
+ (not (editorconfig--disabled-for-majormode major-mode))
+ buffer-file-name
+ (not (editorconfig--disabled-for-filename buffer-file-name)))
+ (editorconfig-apply)))
+
+
+;;;###autoload
+(defun editorconfig-find-current-editorconfig ()
+ "Find the closest .editorconfig file for current file."
+ (interactive)
+ (eval-and-compile (require 'editorconfig-core))
+ (when-let* ((file (editorconfig-core-get-nearest-editorconfig
+ default-directory)))
+ (find-file file)))
+
+;;;###autoload
+(defun editorconfig-display-current-properties ()
+ "Display EditorConfig properties extracted for current buffer."
+ (interactive)
+ (if editorconfig-properties-hash
+ (let ((buf (get-buffer-create "*EditorConfig Properties*"))
+ (file buffer-file-name)
+ (props editorconfig-properties-hash))
+ (with-current-buffer buf
+ (erase-buffer)
+ (insert (format "# EditorConfig for %s\n" file))
+ (maphash (lambda (k v)
+ (insert (format "%S = %s\n" k v)))
+ props))
+ (display-buffer buf))
+ (message "Properties are not applied to current buffer yet.")
+ nil))
+;;;###autoload
+(defalias 'describe-editorconfig-properties
+ #'editorconfig-display-current-properties)
+
+;;;###autoload
+(defun editorconfig-format-buffer()
+ "Format buffer according to .editorconfig indent_style and indent_width."
+ (interactive)
+ (when (string= (gethash 'indent_style editorconfig-properties-hash) "tab")
+ (tabify (point-min) (point-max)))
+ (when (string= (gethash 'indent_style editorconfig-properties-hash) "space")
+ (untabify (point-min) (point-max)))
+ (indent-region (point-min) (point-max)))
+
+
+(provide 'editorconfig-tools)
+;;; editorconfig-tools.el ends here
--- /dev/null
+;;; editorconfig.el --- EditorConfig Emacs Plugin -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2024 EditorConfig Team
+
+;; Author: EditorConfig Team <editorconfigNOSPAMgooglegroups.com>
+;; Package-Version: 20260118.718
+;; Package-Revision: 1e9931d5f38a
+;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
+;; Package-Requires: ((emacs "27.2"))
+;; Keywords: convenience editorconfig
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
+;; or the CONTRIBUTORS file for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU General Public License along with
+;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; EditorConfig helps developers define and maintain consistent
+;; coding styles between different editors and IDEs.
+
+;; The EditorConfig project consists of a file format for defining
+;; coding styles and a collection of text editor plugins that enable
+;; editors to read the file format and adhere to defined styles.
+;; EditorConfig files are easily readable and they work nicely with
+;; version control systems.
+
+;;; Code:
+
+(require 'cl-lib)
+
+(eval-when-compile (require 'subr-x))
+(defvar tex-indent-basic)
+(defvar tex-indent-item)
+(defvar tex-indent-arg)
+(defvar evil-shift-width)
+
+(require 'editorconfig-core)
+
+(defgroup editorconfig nil
+ "EditorConfig Emacs Plugin.
+
+EditorConfig helps developers define and maintain consistent
+coding styles between different editors and IDEs."
+ :tag "EditorConfig"
+ :prefix "editorconfig-"
+ :group 'tools)
+
+(define-obsolete-variable-alias
+ 'edconf-exec-path
+ 'editorconfig-exec-path
+ "0.5")
+(defcustom editorconfig-exec-path
+ "editorconfig"
+ "Path to EditorConfig executable.
+
+Used by `editorconfig--execute-editorconfig-exec'."
+ :type 'string)
+
+(define-obsolete-variable-alias
+ 'edconf-get-properties-function
+ 'editorconfig-get-properties-function
+ "0.5")
+(defcustom editorconfig-get-properties-function
+ #'editorconfig-core-get-properties-hash
+ "A function which gets EditorConfig properties for specified file.
+
+This function will be called with one argument, full path of the target file,
+and should return a hash object containing properties, or nil if any core
+program is not available. Keys of this hash should be symbols of properties,
+and values should be strings of their values.
+
+
+For example, if you always want to use built-in core library instead
+of any EditorConfig executable to get properties, add following to
+your init.el:
+
+ (set-variable \\='editorconfig-get-properties-function
+ #\\='editorconfig-core-get-properties-hash)
+
+Possible known values are:
+
+* `editorconfig-core-get-properties-hash' (default)
+ * Always use built-in Emacs-Lisp implementation to get properties
+* `editorconfig-get-properties'
+ * Use `editorconfig-get-properties-from-exec' when
+ `editorconfig-exec-path' executable is found, otherwise
+ use `editorconfig-core-get-properties-hash'
+* `editorconfig-get-properties-from-exec'
+ * Get properties by executing EditorConfig executable"
+ :type 'function)
+
+(defcustom editorconfig-mode-lighter " EditorConfig"
+ "Command `editorconfig-mode' lighter string."
+ :type 'string)
+
+(define-obsolete-variable-alias
+ 'edconf-custom-hooks
+ 'editorconfig-after-apply-functions
+ "0.5")
+(define-obsolete-variable-alias
+ 'editorconfig-custom-hooks
+ 'editorconfig-after-apply-functions
+ "0.7.14")
+(defcustom editorconfig-after-apply-functions ()
+ "A list of functions after loading common EditorConfig settings.
+
+Each element in this list is a hook function. This hook function
+takes one parameter, which is a property hash table. The value
+of properties can be obtained through gethash function.
+
+The hook does not have to be coding style related; you can add
+whatever functionality you want. For example, the following is
+an example to add a new property emacs_linum to decide whether to
+show line numbers on the left:
+
+ (add-hook \\='editorconfig-after-apply-functions
+ \\='(lambda (props)
+ (let ((show-line-num (gethash \\='emacs_linum props)))
+ (cond ((equal show-line-num \"true\") (linum-mode 1))
+ ((equal show-line-num \"false\") (linum-mode 0))))))
+
+This hook will be run even when there are no matching sections in
+\".editorconfig\", or no \".editorconfig\" file was found at all."
+ :type 'hook)
+
+(defcustom editorconfig-hack-properties-functions ()
+ "A list of function to alter property values before applying them.
+
+These functions will be run after loading \".editorconfig\" files and before
+applying them to current buffer, so that you can alter some properties from
+\".editorconfig\" before they take effect.
+\(Since 2021/08/30 (v0.9.0): Buffer coding-systems are set before running
+this functions, so this variable cannot be used to change coding-systems.)
+
+For example, Makefiles always use tab characters for indentation: you can
+overwrite \"indent_style\" property when current `major-mode' is a
+`makefile-mode' with following code:
+
+ (add-hook \\='editorconfig-hack-properties-functions
+ \\='(lambda (props)
+ (when (derived-mode-p \\='makefile-mode)
+ (puthash \\='indent_style \"tab\" props))))
+
+This hook will be run even when there are no matching sections in
+\".editorconfig\", or no \".editorconfig\" file was found at all."
+ :type 'hook)
+(make-obsolete-variable 'editorconfig-hack-properties-functions
+ "Using `editorconfig-after-apply-functions' instead is recommended,
+ because since 2021/08/30 (v0.9.0) this variable cannot support all properties:
+ charset values will be referenced before running this hook."
+ "v0.9.0")
+
+(define-obsolete-variable-alias
+ 'edconf-indentation-alist
+ 'editorconfig-indentation-alist
+ "0.5")
+(defcustom editorconfig-indentation-alist
+ ;; For contributors: Sort modes in alphabetical order
+ '((ada-mode ada-indent)
+ (ada-ts-mode ada-ts-mode-indent-offset)
+ (awk-mode c-basic-offset)
+ (bash-ts-mode sh-basic-offset
+ sh-indentation)
+ (bpftrace-mode c-basic-offset)
+ (c++-mode c-basic-offset)
+ (c++-ts-mode c-basic-offset
+ c-ts-mode-indent-offset)
+ (c-ts-mode c-basic-offset
+ c-ts-mode-indent-offset)
+ (cmake-mode cmake-tab-width)
+ (cmake-ts-mode cmake-tab-width
+ cmake-ts-mode-indent-offset)
+ (coffee-mode coffee-tab-width)
+ (csharp-mode c-basic-offset)
+ (csharp-ts-mode c-basic-offset
+ csharp-ts-mode-indent-offset)
+ (css-ts-mode css-indent-offset)
+ (d-mode c-basic-offset)
+ (elixir-ts-mode elixir-ts-indent-offset)
+ (emacs-lisp-mode . editorconfig--get-indentation-lisp-mode)
+ (f90-mode f90-associate-indent
+ f90-continuation-indent
+ f90-critical-indent
+ f90-do-indent
+ f90-if-indent
+ f90-program-indent
+ f90-type-indent)
+ (feature-mode feature-indent-offset
+ feature-indent-level)
+ (fsharp-mode fsharp-continuation-offset
+ fsharp-indent-level
+ fsharp-indent-offset)
+ (go-ts-mode go-ts-mode-indent-offset)
+ (gpr-mode gpr-indent)
+ (gpr-ts-mode gpr-ts-mode-indent-offset)
+ (haskell-mode haskell-indent-spaces
+ haskell-indent-offset
+ haskell-indentation-layout-offset
+ haskell-indentation-left-offset
+ haskell-indentation-starter-offset
+ haskell-indentation-where-post-offset
+ haskell-indentation-where-pre-offset
+ shm-indent-spaces)
+ (haxor-mode haxor-tab-width)
+ (html-ts-mode html-ts-mode-indent-offset)
+ (idl-mode c-basic-offset)
+ (jade-mode jade-tab-width)
+ (java-mode c-basic-offset)
+ (java-ts-mode c-basic-offset
+ java-ts-mode-indent-offset)
+ (js-ts-mode js-indent-level)
+ (js-json-mode js-indent-level)
+ (js-jsx-mode js-indent-level sgml-basic-offset)
+ (js2-jsx-mode js2-basic-offset sgml-basic-offset)
+ (json-mode js-indent-level)
+ (json-ts-mode json-ts-mode-indent-offset)
+ (jsonian-mode jsonian-default-indentation)
+ (kotlin-mode kotlin-tab-width)
+ (kotlin-ts-mode kotlin-ts-mode-indent-offset)
+ (latex-mode . editorconfig--get-indentation-latex-mode)
+ (lisp-mode . editorconfig--get-indentation-lisp-mode)
+ (livescript-mode livescript-tab-width)
+ (magik-ts-mode magik-indent-level)
+ (meson-mode meson-indent-basic)
+ (mips-mode mips-tab-width)
+ (mustache-mode mustache-basic-offset)
+ (nxml-mode . editorconfig--get-indentation-nxml-mode)
+ (objc-mode c-basic-offset)
+ (octave-mode octave-block-offset)
+ ;; No need to change `php-mode-coding-style' value for php-mode
+ ;; since we run editorconfig later than it resets `c-basic-offset'.
+ ;; See https://github.com/editorconfig/editorconfig-emacs/issues/116
+ ;; for details.
+ (php-mode c-basic-offset)
+ (php-ts-mode php-ts-mode-indent-offset)
+ (pike-mode c-basic-offset)
+ (protobuf-mode c-basic-offset)
+ (ps-mode ps-mode-tab)
+ (pug-mode pug-tab-width)
+ (python-mode . editorconfig--get-indentation-python-mode)
+ (python-ts-mode . editorconfig--get-indentation-python-mode)
+ (rjsx-mode js-indent-level sgml-basic-offset)
+ (ruby-ts-mode ruby-indent-level)
+ (rust-ts-mode rust-indent-offset
+ rust-ts-mode-indent-offset)
+ (scala-mode scala-indent:step)
+ (scss-mode css-indent-offset)
+ (sh-mode sh-basic-offset sh-indentation)
+ (swift-mode swift-mode:basic-offset)
+ (tcl-mode tcl-indent-level
+ tcl-continued-indent-level)
+ (templ-ts-mode go-ts-mode-indent-offset js-indent-level)
+ (toml-ts-mode toml-ts-mode-indent-offset)
+ (typescript-ts-base-mode typescript-ts-mode-indent-offset)
+ (verilog-mode verilog-indent-level
+ verilog-indent-level-behavioral
+ verilog-indent-level-declaration
+ verilog-indent-level-module
+ verilog-cexp-indent
+ verilog-case-indent)
+ (web-mode . editorconfig--get-indentation-web-mode)
+ (yaml-ts-mode yaml-indent-offset))
+ "Alist of indentation setting methods by modes.
+
+This is a fallback used for those modes which don't set
+`editorconfig-indent-size-vars'.
+
+Each element looks like (MODE . FUNCTION) or (MODE . VARLIST).
+
+If FUNCTION is provided, it will be called with one argument (the indent size)
+when setting the indentation. It should return the list of settings that need
+to be applied, where each setting has the form (VARIABLE . VALUE).
+
+If VARLIST is provided, each element of VARLIST should be the name of
+a variable that we should set to the indent size.
+
+NOTE: Only the **buffer local** value of VARIABLE will be set."
+ :type '(alist :key-type symbol :value-type sexp)
+ :risky t)
+
+(defcustom editorconfig-exclude-modes ()
+ "Modes in which `editorconfig-mode-apply' will not run."
+ :type '(repeat (symbol :tag "Major Mode")))
+
+(defcustom editorconfig-exclude-regexps ()
+ "List of regexp for buffer filenames `editorconfig-mode-apply' will not run.
+
+When variable `buffer-file-name' matches any of the regexps, then
+`editorconfig-mode-apply' will not do its work."
+ :type '(repeat string))
+(with-eval-after-load 'recentf
+ (add-to-list 'editorconfig-exclude-regexps
+ (rx-to-string '(seq string-start
+ (eval (file-truename (expand-file-name recentf-save-file))))
+ t)))
+
+(defcustom editorconfig-trim-whitespaces-mode
+ (when (fboundp 'delete-trailing-whitespace-mode)
+ #'delete-trailing-whitespace-mode)
+ "Buffer local minor-mode to use to trim trailing whitespaces.
+
+If set, enable that mode when `trim_trailing_whitespace` is set to true.
+Otherwise, use `delete-trailing-whitespace'."
+ :type 'function)
+
+(defvar-local editorconfig-properties-hash nil
+ "Hash object of EditorConfig properties that was enabled for current buffer.")
+(put 'editorconfig-properties-hash
+ 'permanent-local
+ t)
+
+(defvar editorconfig-lisp-use-default-indent nil
+ "Selectively ignore the value of indent_size for Lisp files.
+Prevents `lisp-indent-offset' from being set selectively.
+
+nil - `lisp-indent-offset' is always set normally.
+t - `lisp-indent-offset' is never set normally
+ (always use default indent for lisps).
+number - `lisp-indent-offset' is not set only if indent_size is
+ equal to this number. For example, if this is set to 2,
+ `lisp-indent-offset' will not be set only if indent_size is 2.")
+
+(defcustom editorconfig-override-file-local-variables t
+ "Non-nil means editorconfig will override file local variable values."
+ :type 'boolean)
+
+(defcustom editorconfig-override-dir-local-variables t
+ "Non-nil means editorconfig will override values defined in dir-locals.el ."
+ :type 'boolean)
+
+(define-error 'editorconfig-error
+ "Error thrown from editorconfig lib")
+
+(defun editorconfig-error (&rest args)
+ "Signal an `editorconfig-error'.
+Make a message by passing ARGS to `format-message'."
+ (signal 'editorconfig-error (list (apply #'format-message args))))
+
+(defun editorconfig--disabled-for-filename (filename)
+ "Return non-nil when EditorConfig is disabled for FILENAME."
+ (cl-assert (stringp filename))
+ (cl-loop for regexp in editorconfig-exclude-regexps
+ if (string-match regexp filename) return t
+ finally return nil))
+
+(defun editorconfig--disabled-for-majormode (majormode)
+ "Return non-nil when Editorconfig is disabled for MAJORMODE."
+ (cl-assert majormode)
+ (or (provided-mode-derived-p majormode 'special-mode)
+ ;; Some special modes (like `archive-mode') are not derived from
+ ;; `special-mode'
+ (eq (get majormode 'mode-class) 'special)
+ (memq majormode
+ editorconfig-exclude-modes)))
+
+(defun editorconfig-string-integer-p (string)
+ "Return non-nil if STRING represents integer."
+ (and (stringp string)
+ (string-match-p "\\`[0-9]+\\'" string)))
+
+(defun editorconfig--get-indentation-web-mode (size)
+ `((web-mode-indent-style . 2)
+ (web-mode-attr-indent-offset . ,size)
+ (web-mode-attr-value-indent-offset . ,size)
+ (web-mode-code-indent-offset . ,size)
+ (web-mode-css-indent-offset . ,size)
+ (web-mode-markup-indent-offset . ,size)
+ (web-mode-sql-indent-offset . ,size)
+ (web-mode-block-padding . ,size)
+ (web-mode-script-padding . ,size)
+ (web-mode-style-padding . ,size)))
+
+(defun editorconfig--get-indentation-python-mode (size)
+ "Vars to set `python-mode' indent size to SIZE."
+ `((python-indent-offset . ,size) ;For python.el
+ (py-indent-offset . ,size))) ;For python-mode.el
+
+(defun editorconfig--get-indentation-latex-mode (size)
+ "Vars to set `latex-mode' indent size to SIZE."
+ `((tex-indent-basic . ,size)
+ (tex-indent-item . ,size)
+ (tex-indent-arg . ,(* 2 size))
+ ;; For AUCTeX
+ (TeX-brace-indent-level . ,size)
+ (LaTeX-indent-level . ,size)
+ (LaTeX-item-indent . ,(- size))))
+
+(defun editorconfig--get-indentation-nxml-mode (size)
+ "Vars to set `nxml-mode' indent size to SIZE."
+ `((nxml-child-indent . ,size)
+ (nxml-attribute-indent . ,(* 2 size))))
+
+(defun editorconfig--get-indentation-lisp-mode (size)
+ "Set indent size to SIZE for Lisp mode(s)."
+ (when (cond ((null editorconfig-lisp-use-default-indent) t)
+ ((eql t editorconfig-lisp-use-default-indent) nil)
+ ((numberp editorconfig-lisp-use-default-indent)
+ (not (eql size editorconfig-lisp-use-default-indent)))
+ (t t))
+ `((lisp-indent-offset . ,size))))
+
+(cl-defun editorconfig--should-set (symbol)
+ "Determine if editorconfig should set SYMBOL."
+ (display-warning '(editorconfig editorconfig--should-set)
+ (format "symbol: %S"
+ symbol)
+ :debug)
+ (when (and (not editorconfig-override-file-local-variables)
+ (assq symbol file-local-variables-alist))
+ (cl-return-from editorconfig--should-set
+ nil))
+
+ (when (and (not editorconfig-override-dir-local-variables)
+ (assq symbol dir-local-variables-alist))
+ (cl-return-from editorconfig--should-set
+ nil))
+
+ t)
+
+(defvar editorconfig-indent-size-vars
+ #'editorconfig--default-indent-size-function
+ "Rule to use to set a given `indent_size'.
+This should hold the list of variables that need to be set to SIZE
+to tell the indentation code of the current major mode to use a basic
+indentation step of size SIZE.
+It can also take the form of a function, in which case we call it with
+a single SIZE argument (an integer) and it should return a list
+of (VAR . VAL) pairs indicating the variables to set and the values to
+set them to.
+Major modes are expected to set this buffer-locally.")
+
+(defun editorconfig--default-indent-size-function (size)
+ "Guess which variables to set to for the indentation step to have size SIZE.
+This relies on `editorconfig-indentation-alist' supplemented with a crude
+heuristic for those modes not found there."
+ (let ((parents (if (fboundp 'derived-mode-all-parents) ;Emacs-30
+ (derived-mode-all-parents major-mode)
+ (let ((modes nil)
+ (mode major-mode))
+ (while mode
+ (push mode modes)
+ (setq mode (get mode 'derived-mode--parent)))
+ (nreverse modes))))
+ entry)
+ (let ((parents parents))
+ (while (and parents (not entry))
+ (setq entry (assq (pop parents) editorconfig-indentation-alist))))
+ (or
+ (when entry
+ (let ((rule (cdr entry)))
+ ;; Filter out settings of unknown vars.
+ (delq nil
+ (mapcar
+ (lambda (elem)
+ (let ((v (car elem)))
+ (cond
+ ((not (symbolp v))
+ (message "Unsupported element in `editorconfig-indentation-alist': %S" elem))
+ ((boundp v) elem))))
+ (if (functionp rule)
+ (let ((result (funcall rule size)))
+ (if (and (consp (car-safe result))
+ (boundp (caar result)))
+ result
+ (message "Invalid return value for: %S"
+ rule)
+ nil))
+ (mapcar
+ (lambda (elem)
+ (cond
+ ((symbolp elem) `(,elem . ,size))
+ ((consp elem)
+ (message "Old-style entry in editorconfig-indentation-alist: %S" elem)
+ `(,(car elem)
+ . ,(let ((spec (cdr elem)))
+ (cond ((functionp spec) (funcall spec size))
+ ((integerp spec) (* spec size))
+ (t spec)))))))
+ rule))))))
+ ;; Fallback, let's try and guess.
+ (let ((suffixes '("-indent-level" "-basic-offset" "-indent-offset"))
+ (guess ()))
+ (while (and parents (not guess))
+ (let* ((mode (pop parents))
+ (modename (symbol-name mode))
+ (name (substring modename 0
+ (string-match "-mode\\'" modename))))
+ (dolist (suffix suffixes)
+ (let ((sym (intern-soft (concat name suffix))))
+ (when (and sym (boundp sym))
+ (setq guess sym))))))
+ (when guess `((,guess . ,size))))
+ (and (local-variable-p 'smie-rules-function)
+ `((smie-indent-basic . ,size))))))
+
+(defun editorconfig--get-indentation (style &optional size tab_width)
+ "Get indentation vars according to STYLE, SIZE, and TAB_WIDTH."
+ (if tab_width (setq tab_width (string-to-number tab_width)))
+
+ (setq size
+ (cond ((editorconfig-string-integer-p size)
+ (string-to-number size))
+ ((equal size "tab")
+ (or tab_width tab-width))
+ (t
+ nil)))
+
+ `(,@(cond (tab_width `((tab-width . ,tab_width)))
+ ((numberp size) `((tab-width . ,size))))
+
+ ,@(pcase style
+ ("space" `((indent-tabs-mode . nil)))
+ ("tab" `((indent-tabs-mode . t))))
+
+ ,@(when (and size (featurep 'evil))
+ `((evil-shift-width . ,size)))
+
+ ,@(cond
+ ((null size) nil)
+ ((functionp editorconfig-indent-size-vars)
+ (funcall editorconfig-indent-size-vars size))
+ (t (mapcar (lambda (v) `(,v . ,size))
+ editorconfig-indent-size-vars)))))
+
+
+(defun editorconfig-set-indentation (style &optional size tab_width)
+ "Set indentation type from STYLE, SIZE and TAB_WIDTH."
+ (dolist (setting (editorconfig--get-indentation style size tab_width))
+ (when (editorconfig--should-set (car setting))
+ (set (make-local-variable (car setting)) (cdr setting)))))
+
+(defvar-local editorconfig--apply-coding-system-currently nil
+ "Used internally.")
+(put 'editorconfig--apply-coding-system-currently
+ 'permanent-local
+ t)
+
+(defun editorconfig-merge-coding-systems (end-of-line charset)
+ "Return merged coding system symbol of END-OF-LINE and CHARSET."
+ (let ((eol (cond
+ ((equal end-of-line "lf") 'undecided-unix)
+ ((equal end-of-line "cr") 'undecided-mac)
+ ((equal end-of-line "crlf") 'undecided-dos)))
+ (cs (cond
+ ((equal charset "latin1") 'iso-latin-1)
+ ((equal charset "utf-8") 'utf-8)
+ ((equal charset "utf-8-bom") 'utf-8-with-signature)
+ ((equal charset "utf-16be") 'utf-16be-with-signature)
+ ((equal charset "utf-16le") 'utf-16le-with-signature))))
+ (if (and eol cs)
+ (merge-coding-systems cs eol)
+ (or eol cs))))
+
+(cl-defun editorconfig-set-coding-system-revert (end-of-line charset)
+ "Set buffer coding system by END-OF-LINE and CHARSET.
+
+This function will revert buffer when the coding-system has been changed."
+ ;; `editorconfig--advice-find-file-noselect' does not use this function
+ (let ((coding-system (editorconfig-merge-coding-systems end-of-line
+ charset)))
+ (display-warning '(editorconfig editorconfig-set-coding-system-revert)
+ (format "editorconfig-set-coding-system-revert: buffer-file-name: %S | buffer-file-coding-system: %S | coding-system: %S | apply-currently: %S"
+ buffer-file-name
+ buffer-file-coding-system
+ coding-system
+ editorconfig--apply-coding-system-currently)
+ :debug)
+ (when (memq coding-system '(nil undecided))
+ (cl-return-from editorconfig-set-coding-system-revert))
+ (when (and buffer-file-coding-system
+ (memq buffer-file-coding-system
+ (coding-system-aliases (merge-coding-systems coding-system
+ buffer-file-coding-system))))
+ (cl-return-from editorconfig-set-coding-system-revert))
+ (unless (file-readable-p buffer-file-name)
+ (set-buffer-file-coding-system coding-system)
+ (cl-return-from editorconfig-set-coding-system-revert))
+ (unless (memq coding-system
+ (coding-system-aliases editorconfig--apply-coding-system-currently))
+ ;; Revert functions might call `editorconfig-apply' again
+ ;; FIXME: I suspect `editorconfig--apply-coding-system-currently'
+ ;; gymnastics is not needed now that we hook into `find-auto-coding'.
+ (unwind-protect
+ (progn
+ (setq editorconfig--apply-coding-system-currently coding-system)
+ ;; Revert without query if buffer is not modified
+ (let ((revert-without-query '(".")))
+ (revert-buffer-with-coding-system coding-system)))
+ (setq editorconfig--apply-coding-system-currently nil)))))
+
+(defun editorconfig--delete-final-newline ()
+ "Ensure the buffer does not end with a newline.
+Does nothing if the buffer is read-only."
+ (unless buffer-read-only
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-max))
+ (while (looking-at-p "^$")
+ (delete-char -1))))))
+
+(defun editorconfig-set-trailing-nl (final-newline)
+ "Set up requiring final newline by FINAL-NEWLINE.
+
+This function will set `require-final-newline' and `mode-require-final-newline'
+to non-nil when FINAL-NEWLINE is true."
+ (pcase final-newline
+ ("true"
+ ;; keep prefs around how/when the nl is added, if set - otherwise add on save
+ (setq-local require-final-newline (or require-final-newline t))
+ (setq-local mode-require-final-newline (or mode-require-final-newline t))
+ (remove-hook 'before-save-hook
+ #'editorconfig--delete-final-newline t))
+
+ ("false"
+ (setq-local require-final-newline nil)
+ (setq-local mode-require-final-newline nil)
+ (add-hook 'before-save-hook
+ #'editorconfig--delete-final-newline nil t))))
+
+(defun editorconfig--delete-trailing-whitespace ()
+ "Call `delete-trailing-whitespace' unless the buffer is read-only."
+ (unless buffer-read-only (delete-trailing-whitespace)))
+
+(defun editorconfig-set-trailing-ws (trim-trailing-ws)
+ (pcase trim-trailing-ws
+ ("true"
+ (if editorconfig-trim-whitespaces-mode
+ (funcall editorconfig-trim-whitespaces-mode 1)
+ (add-hook 'before-save-hook
+ #'editorconfig--delete-trailing-whitespace nil t)))
+ ("false"
+ (when editorconfig-trim-whitespaces-mode
+ (funcall editorconfig-trim-whitespaces-mode 0))
+ (remove-hook 'before-save-hook
+ #'editorconfig--delete-trailing-whitespace t))))
+
+
+(defun editorconfig-set-line-length (length)
+ "Set the max line length (`fill-column') to LENGTH."
+ (when (and (editorconfig-string-integer-p length)
+ (> (string-to-number length) 0))
+ (setq fill-column (string-to-number length))))
+
+
+(defun editorconfig--execute-editorconfig-exec (filename)
+ "Execute EditorConfig core with FILENAME and return output."
+ (if filename
+ (with-temp-buffer
+ (let ((remote (file-remote-p filename))
+ (remote-localname (file-remote-p filename
+ 'localname)))
+ (display-warning '(editorconfig editorconfig--execute-editorconfig-exec)
+ (format "editorconfig--execute-editorconfig-exec: filename: %S | remote: %S | remote-localname: %S"
+ filename
+ remote
+ remote-localname)
+ :debug)
+ (if remote
+ (progn
+ (cd (concat remote "/"))
+ (setq filename remote-localname))
+ (cd "/")))
+ (display-warning '(editorconfig editorconfig--execute-editorconfig-exec)
+ (format "editorconfig--execute-editorconfig-exec: default-directory: %S | filename: %S"
+ default-directory
+ filename
+ )
+ :debug)
+ (if (eq 0
+ (process-file editorconfig-exec-path nil t nil filename))
+ (buffer-string)
+ (editorconfig-error (buffer-string))))
+ ""))
+
+(defun editorconfig--parse-properties (props-string)
+ "Create properties hash table from PROPS-STRING."
+ (let ((props-list (split-string props-string "\n"))
+ (properties (make-hash-table)))
+ (dolist (prop props-list properties)
+ (let ((key-val (split-string prop " *= *")))
+ (when (> (length key-val) 1)
+ (let ((key (intern (car key-val)))
+ (val (mapconcat #'identity (cdr key-val) "")))
+ (puthash key val properties)))))))
+
+(defun editorconfig-get-properties-from-exec (filename)
+ "Get EditorConfig properties of file FILENAME.
+
+This function uses value of `editorconfig-exec-path' to get properties."
+ (if (executable-find editorconfig-exec-path)
+ (editorconfig--parse-properties (editorconfig--execute-editorconfig-exec filename))
+ (editorconfig-error "Unable to find editorconfig executable")))
+
+(defun editorconfig-get-properties (filename)
+ "Get EditorConfig properties for file FILENAME.
+
+It calls `editorconfig-get-properties-from-exec' if
+`editorconfig-exec-path' is found, otherwise
+`editorconfig-core-get-properties-hash'."
+ (if (and (executable-find editorconfig-exec-path)
+ (not (file-remote-p filename)))
+ (editorconfig-get-properties-from-exec filename)
+ (require 'editorconfig-core)
+ (editorconfig-core-get-properties-hash filename)))
+
+(defun editorconfig-call-get-properties-function (filename)
+ "Call `editorconfig-get-properties-function' with FILENAME and return result.
+
+This function also removes `unset' properties and calls
+`editorconfig-hack-properties-functions'."
+ (unless (functionp editorconfig-get-properties-function)
+ (editorconfig-error "Invalid editorconfig-get-properties-function value"))
+ (if (stringp filename)
+ (setq filename (expand-file-name filename))
+ (editorconfig-error "Invalid argument: %S" filename))
+ (let ((props nil))
+ (condition-case err
+ (setq props (funcall editorconfig-get-properties-function
+ filename))
+ (error
+ (editorconfig-error "Error from editorconfig-get-properties-function: %S"
+ err)))
+ (cl-loop for k being the hash-keys of props using (hash-values v)
+ when (equal v "unset") do (remhash k props))
+ props))
+
+(defun editorconfig-set-local-variables (props)
+ "Set buffer variables according to EditorConfig PROPS."
+ (editorconfig-set-indentation (gethash 'indent_style props)
+ (gethash 'indent_size props)
+ (gethash 'tab_width props))
+ (editorconfig-set-trailing-nl (gethash 'insert_final_newline props))
+ (editorconfig-set-trailing-ws (gethash 'trim_trailing_whitespace props))
+ (editorconfig-set-line-length (gethash 'max_line_length props)))
+
+
+(defun editorconfig-major-mode-hook ()
+ "Function to run when `major-mode' has been changed.
+
+This functions does not reload .editorconfig file, just sets local variables
+again. Changing major mode can reset these variables.
+
+This function also executes `editorconfig-after-apply-functions' functions."
+ (display-warning '(editorconfig editorconfig-major-mode-hook)
+ (format "editorconfig-major-mode-hook: editorconfig-mode: %S, major-mode: %S, -properties-hash: %S"
+ (and (boundp 'editorconfig-mode)
+ editorconfig-mode)
+ major-mode
+ editorconfig-properties-hash)
+ :debug)
+ (when (and (bound-and-true-p editorconfig-mode)
+ editorconfig-properties-hash)
+ (editorconfig-set-local-variables editorconfig-properties-hash)
+ (condition-case err
+ (run-hook-with-args 'editorconfig-after-apply-functions editorconfig-properties-hash)
+ (error
+ (display-warning '(editorconfig editorconfig-major-mode-hook)
+ (format "Error while running `editorconfig-after-apply-functions': %S"
+ err))))))
+
+;; This is a new var in Emacs≥30.
+;; We dyn-bind it in our `editorconfig--advice-find-auto-coding' advice
+;; to mimic the Emacs-30 behavior.
+(defvar auto-coding-file-name)
+
+(defun editorconfig--advice-find-auto-coding (filename &rest _args)
+ "Consult `charset' setting of EditorConfig."
+ (let ((cs (let ((auto-coding-file-name filename))
+ (editorconfig--get-coding-system))))
+ (when cs (cons cs 'EditorConfig))))
+
+(defun editorconfig--advice-find-file-noselect (f filename &rest args)
+ "Get EditorConfig properties and apply them to buffer to be visited.
+
+This function should be added as an advice function to `find-file-noselect'.
+F is that function, and FILENAME and ARGS are arguments passed to F."
+ (let ((props nil)
+ (ret nil))
+ (condition-case err
+ (when (stringp filename)
+ (setq props (editorconfig-call-get-properties-function filename)))
+ (error
+ (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
+ (format "Failed to get properties, styles will not be applied: %S"
+ err)
+ :warning)))
+
+ (setq ret (apply f filename args))
+
+ (condition-case err
+ (with-current-buffer ret
+ (when props
+
+ ;; NOTE: hack-properties-functions cannot affect coding-system value,
+ ;; because it has to be set before initializing buffers.
+ (condition-case err
+ (run-hook-with-args 'editorconfig-hack-properties-functions props)
+ (error
+ (display-warning '(editorconfig editorconfig-hack-properties-functions)
+ (format "Error while running editorconfig-hack-properties-functions, abort running hook: %S"
+ err)
+ :warning)))
+ (setq editorconfig-properties-hash props)
+ ;; When initializing buffer, `editorconfig-major-mode-hook'
+ ;; will be called before setting `editorconfig-properties-hash', so
+ ;; execute this explicitly here.
+ (editorconfig-set-local-variables props)
+
+ (condition-case err
+ (run-hook-with-args 'editorconfig-after-apply-functions props)
+ (error
+ (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
+ (format "Error while running `editorconfig-after-apply-functions': %S"
+ err))))))
+ (error
+ (display-warning '(editorconfig editorconfig--advice-find-file-noselect)
+ (format "Error while setting variables from EditorConfig: %S" err))))
+ ret))
+
+(defvar editorconfig--getting-coding-system nil)
+
+(defun editorconfig--get-coding-system (&optional _size)
+ "Return the coding system to use according to EditorConfig.
+Meant to be used on `auto-coding-functions'."
+ ;; Not only we don't want that an error in the `.editorconfig' file
+ ;; prevents opening a file but we don't want an error to be dropped on
+ ;; the floor by some `ignore-errors' higher up.
+ (with-demoted-errors "EditorConfig: %S"
+ (when (and (stringp auto-coding-file-name)
+ (file-name-absolute-p auto-coding-file-name)
+ ;; Don't recurse infinitely.
+ (not (member auto-coding-file-name
+ editorconfig--getting-coding-system)))
+ (let* ((editorconfig--getting-coding-system
+ (cons auto-coding-file-name editorconfig--getting-coding-system))
+ (props (editorconfig-call-get-properties-function
+ auto-coding-file-name)))
+ (editorconfig-merge-coding-systems (gethash 'end_of_line props)
+ (gethash 'charset props))))))
+
+;;;###autoload
+(define-minor-mode editorconfig-mode
+ "Toggle EditorConfig feature.
+
+To disable EditorConfig in some buffers, modify
+`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'."
+ :global t
+ :lighter editorconfig-mode-lighter
+ (let ((modehooks '(prog-mode-hook
+ text-mode-hook
+ ;; Some modes call `kill-all-local-variables' in their init
+ ;; code, which clears some values set by editorconfig.
+ ;; For those modes, editorconfig-apply need to be called
+ ;; explicitly through their hooks.
+ rpm-spec-mode-hook)))
+ (if editorconfig-mode
+ (progn
+ (advice-add 'find-file-noselect :around #'editorconfig--advice-find-file-noselect)
+ (advice-add 'find-auto-coding :after-until
+ #'editorconfig--advice-find-auto-coding)
+ (dolist (hook modehooks)
+ (add-hook hook
+ #'editorconfig-major-mode-hook
+ t)))
+ (advice-remove 'find-file-noselect #'editorconfig--advice-find-file-noselect)
+ (advice-remove 'find-auto-coding
+ #'editorconfig--advice-find-auto-coding)
+ (dolist (hook modehooks)
+ (remove-hook hook #'editorconfig-major-mode-hook)))))
+
+
+;; (defconst editorconfig--version
+;; (eval-when-compile
+;; (require 'lisp-mnt)
+;; (declare-function lm-version "lisp-mnt" nil)
+;; (lm-version))
+;; "EditorConfig version.")
+
+;;;###autoload
+(defun editorconfig-version (&optional show-version)
+ "Get EditorConfig version as string.
+
+If called interactively or if SHOW-VERSION is non-nil, show the
+version in the echo area and the messages buffer."
+ (interactive (list t))
+ (let ((version-full
+ (if (fboundp 'package-get-version) ;Emacs≥27
+ (package-get-version)
+ (let* ((version
+ (with-temp-buffer
+ (require 'find-func)
+ (declare-function find-library-name "find-func" (library))
+ (insert-file-contents (find-library-name "editorconfig"))
+ (require 'lisp-mnt)
+ (declare-function lm-version "lisp-mnt" nil)
+ (lm-version)))
+ (pkg (and (eval-and-compile (require 'package nil t))
+ (cadr (assq 'editorconfig
+ package-alist))))
+ (pkg-version (and pkg (package-version-join
+ (package-desc-version pkg)))))
+ (if (and pkg-version
+ (not (string= version pkg-version)))
+ (concat version "-" pkg-version)
+ version)))))
+ (when show-version
+ (message "EditorConfig Emacs v%s" version-full))
+ version-full))
+
+(provide 'editorconfig)
+;;; editorconfig.el ends here
--- /dev/null
+This is editorconfig.info, produced by makeinfo version 6.8 from
+editorconfig.texi.
+
+INFO-DIR-SECTION Emacs
+START-INFO-DIR-ENTRY
+* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
+END-INFO-DIR-ENTRY
+
+\1f
+File: editorconfig.info, Node: Top, Next: Getting Started, Up: (dir)
+
+1 EditorConfig Emacs Plugin
+***************************
+
+This is an EditorConfig (https://editorconfig.org) plugin for Emacs
+(https://www.gnu.org/software/emacs/).
+
+* Menu:
+
+* Getting Started::
+* Supported properties::
+* Customize::
+* Troubleshooting::
+* Submitting Bugs and Feature Requests::
+* License::
+
+\1f
+File: editorconfig.info, Node: Getting Started, Next: Supported properties, Prev: Top, Up: Top
+
+1.1 Getting Started
+===================
+
+* Menu:
+
+* packageel::
+* use-package::
+* Manual installation::
+
+\1f
+File: editorconfig.info, Node: packageel, Next: use-package, Up: Getting Started
+
+1.1.1 package.el
+----------------
+
+This package is available from MELPA (https://melpa.org/#/editorconfig),
+MELPA Stable (https://stable.melpa.org/#/editorconfig) and NonGNU ELPA
+(http://elpa.nongnu.org/nongnu/editorconfig.html). Install from these
+repositories and enable global minor-mode 'editorconfig-mode':
+
+(editorconfig-mode 1)
+
+ Normally, enabling 'editorconfig-mode' should be enough for this
+plugin to work: all other configurations are optional. This mode sets
+up hooks so that EditorConfig properties will be loaded and applied to
+the new buffers automatically when visiting files.
+
+\1f
+File: editorconfig.info, Node: use-package, Next: Manual installation, Prev: packageel, Up: Getting Started
+
+1.1.2 use-package
+-----------------
+
+If you use *use-package* (https://www.emacswiki.org/emacs/UsePackage),
+add the following to your 'init.el' file:
+
+(use-package editorconfig
+ :ensure t
+ :config
+ (editorconfig-mode 1))
+
+\1f
+File: editorconfig.info, Node: Manual installation, Prev: use-package, Up: Getting Started
+
+1.1.3 Manual installation
+-------------------------
+
+Copy all '.el' files in this repository to '~/.emacs.d/lisp' and add the
+following:
+
+(add-to-list 'load-path "~/.emacs.d/lisp")
+(require 'editorconfig)
+(editorconfig-mode 1)
+
+\1f
+File: editorconfig.info, Node: Supported properties, Next: Customize, Prev: Getting Started, Up: Top
+
+1.2 Supported properties
+========================
+
+Current Emacs plugin coverage for EditorConfig's properties
+(https://editorconfig.org/#supported-properties):
+
+ * 'indent_style'
+ * 'indent_size'
+ * 'tab_width'
+ * 'end_of_line'
+ * 'charset'
+ * 'trim_trailing_whitespace'
+ * 'insert_final_newline = true' is supported
+ * 'insert_final_newline = false' is not enforced (as in trailing
+ newlines actually being removed automagically), we just
+ buffer-locally override any preferences that would auto-add them to
+ files '.editorconfig' marks as trailing-newline-free
+ * 'max_line_length'
+ * 'file_type_ext' (Experimental) (See below)
+ * 'file_type_emacs' (Experimental) (See below)
+ * 'root' (only used by EditorConfig core)
+
+ Not yet covered properties marked with over-strike - pull requests
+implementing missing features warmly welcomed! Typically, you will want
+to tie these to native functionality, or the configuration of existing
+packages handling the feature.
+
+ As several packages have their own handling of, say, indentation, we
+might not yet cover some mode you use, but we try to add the ones that
+show up on our radar.
+
+* Menu:
+
+* File Type file_type_ext file_type_emacs::
+
+\1f
+File: editorconfig.info, Node: File Type file_type_ext file_type_emacs, Up: Supported properties
+
+1.2.1 File Type (file_type_ext, file_type_emacs)
+------------------------------------------------
+
+File-type feature is currently disabled, because this package is now
+undergoing big internal refactoring. For those who want this
+functionality, please consider using editorconfig-custom-majormode
+(https://github.com/10sr/editorconfig-custom-majormode-el).
+
+\1f
+File: editorconfig.info, Node: Customize, Next: Troubleshooting, Prev: Supported properties, Up: Top
+
+1.3 Customize
+=============
+
+'editorconfig-emacs' provides some customize variables.
+
+ Here are some of these variables: for the full list of available
+variables, type M-x customize-group [RET] editorconfig [RET].
+
+* Menu:
+
+* editorconfig-trim-whitespaces-mode::
+* editorconfig-after-apply-functions::
+* editorconfig-hack-properties-functions::
+
+\1f
+File: editorconfig.info, Node: editorconfig-trim-whitespaces-mode, Next: editorconfig-after-apply-functions, Up: Customize
+
+1.3.1 'editorconfig-trim-whitespaces-mode'
+------------------------------------------
+
+Buffer local minor-mode to use to trim trailing whitespaces.
+
+ If set, editorconfig will enable/disable this mode in accord with
+'trim_trailing_whitespace' property in '.editorconfig'. Otherwise, use
+Emacs built-in 'delete-trailing-whitespace' function.
+
+ One possible value is 'ws-butler-mode'
+(https://github.com/lewang/ws-butler), with which only lines touched get
+trimmed. To use it, add following to your init.el:
+
+(setq editorconfig-trim-whitespaces-mode
+ 'ws-butler-mode)
+
+\1f
+File: editorconfig.info, Node: editorconfig-after-apply-functions, Next: editorconfig-hack-properties-functions, Prev: editorconfig-trim-whitespaces-mode, Up: Customize
+
+1.3.2 'editorconfig-after-apply-functions'
+------------------------------------------
+
+(Formerly 'editorconfig-custom-hooks')
+
+ A list of functions which will be called after loading common
+EditorConfig settings, when you can set some custom variables.
+
+ For example, 'web-mode' has several variables for indentation offset
+size and EditorConfig sets them at once by 'indent_size'. You can stop
+indenting only blocks of 'web-mode' by adding following to your init.el:
+
+(add-hook 'editorconfig-after-apply-functions
+ (lambda (props) (setq web-mode-block-padding 0)))
+
+\1f
+File: editorconfig.info, Node: editorconfig-hack-properties-functions, Prev: editorconfig-after-apply-functions, Up: Customize
+
+1.3.3 'editorconfig-hack-properties-functions'
+----------------------------------------------
+
+A list of functions to alter property values before applying them.
+
+ These functions will be run after loading ".editorconfig" files and
+before applying them to current buffer, so that you can alter some
+properties from ".editorconfig" before they take effect.
+
+ For example, Makefile files always use tab characters for
+indentation: you can overwrite "indent_style" property when current
+'major-mode' is 'makefile-mode':
+
+(add-hook 'editorconfig-hack-properties-functions
+ '(lambda (props)
+ (when (derived-mode-p 'makefile-mode)
+ (puthash 'indent_style "tab" props))))
+
+\1f
+File: editorconfig.info, Node: Troubleshooting, Next: Submitting Bugs and Feature Requests, Prev: Customize, Up: Top
+
+1.4 Troubleshooting
+===================
+
+Enabling 'editorconfig-mode' should be enough for normal cases.
+
+ When EditorConfig properties are not effective for unknown reason, we
+recommend first trying 'M-x editorconfig-display-current-properties'.
+
+ This command will open a new buffer and display the EditorConfig
+properties loaded for current buffer. You can check if EditorConfig
+properties were not read for buffers at all, or they were loaded but did
+not take effect for some other reasons.
+
+* Menu:
+
+* Indentation for new major-modes::
+* Not work at all for FOO-mode!::
+
+\1f
+File: editorconfig.info, Node: Indentation for new major-modes, Next: Not work at all for FOO-mode!, Up: Troubleshooting
+
+1.4.1 Indentation for new major-modes
+-------------------------------------
+
+Because most Emacs major-modes have their own indentation settings, this
+plugin requires explicit support for each major-mode for 'indent_size'
+property.
+
+ By default this plugin ships with settings for many major-modes, but,
+sorry to say, it cannot be perfect. Especially it is difficult to
+support brand-new major-modes. Please feel free to submit issue or
+pull-request for such major-mode!
+
+ Supported major-modes and their indentation configs are defined in
+the variable 'editorconfig-indentation-alist'.
+
+\1f
+File: editorconfig.info, Node: Not work at all for FOO-mode!, Prev: Indentation for new major-modes, Up: Troubleshooting
+
+1.4.2 Not work at all for FOO-mode!
+-----------------------------------
+
+Most cases properties are loaded just after visiting files when
+'editorconfig-mode' is enabled. But it is known that there are
+major-modes that this mechanism does not work for and require explicit
+call of 'editorconfig-apply'.
+
+ Typically it will occur when the major-mode is not defined using
+'define-derived-mode' ('rpm-spec-mode' is an example for this). Please
+feel free to submit issues if you find such modes!
+
+\1f
+File: editorconfig.info, Node: Submitting Bugs and Feature Requests, Next: License, Prev: Troubleshooting, Up: Top
+
+1.5 Submitting Bugs and Feature Requests
+========================================
+
+Bugs, feature requests, and other issues should be submitted to the
+issue tracker: https://github.com/editorconfig/editorconfig-emacs/issues
+
+* Menu:
+
+* Development::
+
+\1f
+File: editorconfig.info, Node: Development, Up: Submitting Bugs and Feature Requests
+
+1.5.1 Development
+-----------------
+
+Make and CMake (https://cmake.org) must be installed to run the tests
+locally:
+
+$ make check
+
+ To start a new Emacs process with current '*.el' and without loading
+user init file, run:
+
+$ make sandbox
+
+\1f
+File: editorconfig.info, Node: License, Prev: Submitting Bugs and Feature Requests, Up: Top
+
+1.6 License
+===========
+
+EditorConfig Emacs Plugin is free software: you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
+\1f
+Tag Table:
+Node: Top\7f208
+Ref: #editorconfig-emacs-plugin\7f340
+Node: Getting Started\7f590
+Ref: #getting-started\7f733
+Node: packageel\7f797
+Ref: #package.el\7f919
+Node: use-package\7f1483
+Ref: #use-package\7f1635
+Node: Manual installation\7f1823
+Ref: #manual-installation\7f1973
+Node: Supported properties\7f2148
+Ref: #supported-properties\7f2307
+Node: File Type file_type_ext file_type_emacs\7f3481
+Ref: #file-type-file_type_ext-file_type_emacs\7f3682
+Node: Customize\7f3941
+Ref: #customize\7f4078
+Node: editorconfig-trim-whitespaces-mode\7f4397
+Ref: #editorconfig-trim-whitespaces-mode\7f4613
+Node: editorconfig-after-apply-functions\7f5104
+Ref: #editorconfig-after-apply-functions\7f5367
+Node: editorconfig-hack-properties-functions\7f5853
+Ref: #editorconfig-hack-properties-functions\7f6081
+Node: Troubleshooting\7f6691
+Ref: #troubleshooting\7f6856
+Node: Indentation for new major-modes\7f7396
+Ref: #indentation-for-new-major-modes\7f7600
+Node: Not work at all for FOO-mode!\7f8116
+Ref: #not-work-at-all-for-foo-mode\7f8316
+Node: Submitting Bugs and Feature Requests\7f8738
+Ref: #submitting-bugs-and-feature-requests\7f8943
+Node: Development\7f9111
+Ref: #development\7f9238
+Node: License\7f9442
+Ref: #license\7f9565
+\1f
+End Tag Table
+
+\1f
+Local Variables:
+coding: utf-8
+End: