[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] scratch/editorconfig eff8ad8f30: WiP
From: |
Stefan Monnier |
Subject: |
[nongnu] scratch/editorconfig eff8ad8f30: WiP |
Date: |
Tue, 11 Jun 2024 19:04:47 -0400 (EDT) |
branch: scratch/editorconfig
commit eff8ad8f308a69d6df3d604d43a231a45bd059b1
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
WiP
---
.dir-locals.el | 4 ++
editorconfig-core-handle.el | 5 +--
editorconfig-core.el | 38 +++++++++--------
editorconfig-exec.el | 100 ++++++++++++++++++++++++++++++++++++++++++++
editorconfig-fnmatch.el | 2 +-
editorconfig-tools.el | 2 +-
editorconfig.el | 76 ---------------------------------
7 files changed, 127 insertions(+), 100 deletions(-)
diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000000..970a416e6f
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,4 @@
+ ;;; Directory Local Variables -*- no-byte-compile: t -*-
+ ;;; For more information see (info "(emacs) Directory Variables")
+
+((emacs-lisp-mode . ((sentence-end-double-space . t))))
diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el
index d225e1456b..ac8c0889af 100644
--- a/editorconfig-core-handle.el
+++ b/editorconfig-core-handle.el
@@ -115,6 +115,7 @@ If HANDLE is nil return nil."
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))))
(cl-loop for section in (editorconfig-core-handle-sections handle)
@@ -122,10 +123,6 @@ If HANDLE is nil return nil."
file
dir)
when props collect (copy-alist props)))))
-(make-obsolete 'editorconfig-core-handle-get-properties
- 'editorconfig-core-handle-get-properties-hash
- "0.8.0")
-
(defun editorconfig-core-handle-get-properties-hash (handle file)
"Return hash of properties from HANDLE for FILE.
diff --git a/editorconfig-core.el b/editorconfig-core.el
index c7b52deaaf..84bf94e220 100644
--- a/editorconfig-core.el
+++ b/editorconfig-core.el
@@ -85,12 +85,11 @@ RESULT is used internally and normally should not be used."
(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))
+ (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
@@ -98,21 +97,21 @@ RESULT is used internally and normally should not be used."
".editorconfig")))))
(editorconfig-core-handle-path handle)))
-;;;###autoload
-(defun 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 function returns an alist of properties. Each element will
-look like (KEY . VALUE)."
- (let ((hash (editorconfig-core-get-properties-hash file confname
confversion))
- (result nil))
- (maphash (lambda (key value)
- (add-to-list 'result (cons (symbol-name key) value)))
- hash)
- result))
+;; Not used.
+;;(defun 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 function returns an alist of properties. Each element will
+;;look like (KEY . VALUE)."
+;; (let ((hash (editorconfig-core-get-properties-hash file confname
confversion))
+;; (result nil))
+;; (maphash (lambda (key value)
+;; (add-to-list 'result (cons (symbol-name key) value)))
+;; hash)
+;; result))
(defun editorconfig-core--hash-merge (into update)
"Merge two hashes INTO and UPDATE.
@@ -122,7 +121,6 @@ When the same key exists in both two hashes, values of
UPDATE takes precedence."
(maphash (lambda (key value) (puthash key value into)) update)
into)
-;;;###autoload
(defun editorconfig-core-get-properties-hash (&optional file confname
confversion)
"Get EditorConfig properties for FILE.
If FILE is not given, use currently visiting file.
@@ -145,12 +143,14 @@ hash object instead."
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)))
;; Add indent_size property
+ ;; FIXME: Why? Which part of the spec requires that?
(let ((v-indent-size (gethash 'indent_size result))
(v-indent-style (gethash 'indent_style result)))
(when (and (not v-indent-size)
@@ -162,6 +162,7 @@ hash object instead."
"tab"
result)))
;; Add tab_width property
+ ;; FIXME: Why? Which part of the spec requires that?
(let ((v-indent-size (gethash 'indent_size result))
(v-tab-width (gethash 'tab_width result)))
(when (and v-indent-size
@@ -169,6 +170,7 @@ hash object instead."
(not (string= v-indent-size "tab")))
(puthash 'tab_width v-indent-size result)))
;; Update indent-size property
+ ;; FIXME: Why? Which part of the spec requires that?
(let ((v-indent-size (gethash 'indent_size result))
(v-tab-width (gethash 'tab_width result)))
(when (and v-indent-size
diff --git a/editorconfig-exec.el b/editorconfig-exec.el
new file mode 100644
index 0000000000..070508b78c
--- /dev/null
+++ b/editorconfig-exec.el
@@ -0,0 +1,100 @@
+;;; editorconfig-exec.el --- Get EditorConfig info via executable -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2011-2024 EditorConfig Team
+
+;; Author: EditorConfig Team <editorconfig@googlegroups.com>
+
+;; 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:
+
+;;; Code:
+
+(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'."
+ :group 'editorconfig
+ :type 'string)
+
+(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)))
+
+(provide 'editorconfig-exec)
+;;; editorconfig-exec.el ends here.
diff --git a/editorconfig-fnmatch.el b/editorconfig-fnmatch.el
index 25a344dc2e..520aeb16c2 100644
--- a/editorconfig-fnmatch.el
+++ b/editorconfig-fnmatch.el
@@ -234,7 +234,7 @@ translation is found for PATTERN."
(number-end (string-to-number (match-string 2
pattern-sub))))
(setq result `(,@result ,(concat "\\(?:"
- (mapconcat
'number-to-string
+ (mapconcat
#'number-to-string
(cl-loop
for i from number-start to number-end
collect i)
"\\|")
diff --git a/editorconfig-tools.el b/editorconfig-tools.el
index 12c4057714..31f7c17ba2 100644
--- a/editorconfig-tools.el
+++ b/editorconfig-tools.el
@@ -115,7 +115,7 @@ any of regexps in `editorconfig-exclude-regexps'."
nil))
;;;###autoload
(defalias 'describe-editorconfig-properties
- 'editorconfig-display-current-properties)
+ #'editorconfig-display-current-properties)
;;;###autoload
(defun editorconfig-format-buffer()
diff --git a/editorconfig.el b/editorconfig.el
index 1606d94413..ad86f7949c 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -60,17 +60,6 @@ coding styles between different editors and IDEs."
: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
@@ -628,67 +617,6 @@ This function will revert buffer when the coding-system
has been changed."
`((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.
@@ -974,7 +902,3 @@ version in the echo area and the messages buffer."
(provide 'editorconfig)
;;; editorconfig.el ends here
-
-;; Local Variables:
-;; sentence-end-double-space: t
-;; End:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] scratch/editorconfig eff8ad8f30: WiP,
Stefan Monnier <=