forked from editorconfig/editorconfig-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditorconfig-el
executable file
·127 lines (106 loc) · 4.31 KB
/
editorconfig-el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
:;#-*-Emacs-Lisp-*-
:;test -n "$EMACS_BIN" || EMACS_BIN=emacs
:;exec "$EMACS_BIN" -batch -Q --eval '(setq debug-on-error t)' -l "$0" -- "$@"
;; editorconfig-el --- EditorConfig Core executable in Emacs Lisp
;; Copyright (C) 2011-2020 EditorConfig Team
;; Author: EditorConfig Team <editorconfig@googlegroups.com>
;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
;; 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 executable is mainly for testing core feature, and not intended to be
;; used by users.
;;; Code:
(when (getenv "EDITORCONFIG_CORE_LIBRARY_PATH")
(setq load-path
(append (split-string (getenv "EDITORCONFIG_CORE_LIBRARY_PATH")
":")
load-path)))
(require 'cl-lib)
(require 'editorconfig) ; For `editorconfig-version'
(require 'editorconfig-core)
(defconst editorconfig-bin-help-message
"Usage: editorconfig [-f <configname>] [-b <configversion>] [-h|--help]
[-v|--version] [<filepath> ...]
Options:
-f <configname> Specify config filename other than \".editorconfig\"
-b <configversion> Specify config format version
-h|--help Print this help message
-v|--version Display version information
<filepath> ... File paths to get EditorConfig properties"
"Help message of EditorConfig executable.")
(defun editorconfig-bin-parse-args
(argv &optional confname version)
"Parse arguments and return list.
List returned will be looked like (FILES CONFNAME VERSION).
If either -v, --version, -h or --help option apprears, exit emacs immediately
with required output."
(unless argv
(message editorconfig-bin-help-message)
(kill-emacs 0))
(cl-case (intern (car argv))
(-f
(editorconfig-bin-parse-args (cddr argv)
(cadr argv)
version))
(-b
(editorconfig-bin-parse-args (cddr argv)
confname
(cadr argv)))
((-h --help)
(message editorconfig-bin-help-message)
(kill-emacs 0))
((-v --version)
(princ (format "EditorConfig-EmacsLisp Version %s\n"
(editorconfig-version)))
(kill-emacs 0))
(otherwise
(when (and argv
(string-match-p "^-"
(car argv)))
(error "Invalid option: %s"
(car argv)))
(list argv
confname
version))
))
(defun main (argv)
;; TODO: Read file list from stdin if - is given as FILENAME
(let ((parsed (editorconfig-bin-parse-args argv)))
(cl-case (length (car parsed))
(0
nil)
(1
(dolist (p (editorconfig-core-get-properties (caar parsed)
(nth 1 parsed)
(nth 2 parsed)))
(princ (format "%s=%s\n"
(car p)
(cdr p)))))
(otherwise
(dolist (file (car parsed))
(princ (format "[%s]\n"
file))
(dolist (p (editorconfig-core-get-properties file
(nth 1 parsed)
(nth 2 parsed)))
(princ (format "%s=%s\n"
(car p)
(cdr p))))))))
0)
;; car of command-line-args-left is "--"
(kill-emacs (main (cdr command-line-args-left)))
;;; editorconfig-el ends here