From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#70105: 30.0.50; Emacs should support EditorConfig out of the box Date: Wed, 19 Jun 2024 06:01:16 +0000 Message-ID: References: <867chibhqi.fsf@gnu.org> <86frtnd2e6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13182"; mail-complaints-to="usenet@ciao.gmane.io" Cc: jcs090218@gmail.com, bjorn.bidar@thaodan.de, 8slashes+git@gmail.com, 70105@debbugs.gnu.org To: Stefan Monnier , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 19 08:03:12 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sJoPW-0003Cv-Vk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jun 2024 08:03:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJoPN-0004k2-2e; Wed, 19 Jun 2024 02:03:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJoPL-0004jl-T9 for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2024 02:02:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJoPL-00043r-Ku for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2024 02:02:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJoPO-0000hs-HZ for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2024 02:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Jun 2024 06:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70105 X-GNU-PR-Package: emacs Original-Received: via spool by 70105-submit@debbugs.gnu.org id=B70105.17187769492669 (code B ref 70105); Wed, 19 Jun 2024 06:03:02 +0000 Original-Received: (at 70105) by debbugs.gnu.org; 19 Jun 2024 06:02:29 +0000 Original-Received: from localhost ([127.0.0.1]:34119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJoOq-0000gy-UH for submit@debbugs.gnu.org; Wed, 19 Jun 2024 02:02:29 -0400 Original-Received: from mail-ed1-f42.google.com ([209.85.208.42]:55592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJoOo-0000gj-BQ for 70105@debbugs.gnu.org; Wed, 19 Jun 2024 02:02:27 -0400 Original-Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-57cce3bc8c6so4791073a12.3 for <70105@debbugs.gnu.org>; Tue, 18 Jun 2024 23:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718776877; x=1719381677; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:from:to:cc:subject:date :message-id:reply-to; bh=cBphvp7VBow9UDJfPTkVBw6dI16oG8xoHJ6JKB2MVK4=; b=VWUTBZV7l4jVqPk9YeG4dCWOfXH+VZuEWGdnybzN7xFJrLn9QZdpREc03NCX2bBgH9 ufquOBw02k6HYYudZ5cuoQY1idm8IPPO6kOx7yXEPTG7f92uYmqXCLoKY5yBSXju+cNv jUcfK3ODIGjv2F1iGzxiTaBTIkoLggsBwyJOUgsLAJ/40zbz4XcS6J40OJzVB2p5fiFl zR1wtJZSAWFLa9btl4n67HyzAVaJM7AyqAZxm3t4cmOk2LLf665uamgo9SfB91VAqn7m D3xkmelwLAaHUtmXnlVJgcBuy112fpK7Z6sjzyn3eErHyL1wxC6pe/Cg1VFwjkUEgapM dHSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718776877; x=1719381677; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=cBphvp7VBow9UDJfPTkVBw6dI16oG8xoHJ6JKB2MVK4=; b=RQoYd/9GvZFuTF6TRHPfvaBNt9Rt6o7XyhpFg4V2XzTMasOq6oBwer0z3tTueQ1clD GbNdAahyjPX6Rs8SzwmRtt27lRy5T0Nz0JteZJgtwGxtljXvov+TiNfXNz9uwBzT8EBq 8CNbhGN01QwMYJnXphGSP4b2/8NZC785rQaz5SLw1SknSJyzLh6a7L2o9R4RDcCRqv84 yL1tho9M2j59VWljJ4wOapyyRBhyjgaQskqyUVwihTXk7WEeCo5suzsq/h76zj+EpNr1 WvHA7fO5OSL6/Y3dgJLQzD/DRlujbHMoVFY4jm7sTsXZEUP1RhmX9cN+jaH4bapHzc+T JETA== X-Forwarded-Encrypted: i=1; AJvYcCWseRKsecxgZvKcW8AOXtOeXaujiKIOmjf381WAxwIjd6jhp5uPO1A9AazgZ6zM56Ba31k0f95DxgkCAkmdF4vuWB0WdQA= X-Gm-Message-State: AOJu0YwVj9tuJ5patjUbUKRYaOJyAIf3q/tZ+SCSzUn3RNM5E61+D4Dn bMsSbs6iK0rv1JoYQHH1bRxVb4+tR2yCmsb6AVx7/CiNOGuoekjWuoIIoBq2hpGeBn9XOaKpbZ5 ACGhShari9pS++/U7YJlmr1vVBZA= X-Google-Smtp-Source: AGHT+IEqbKcCwX1Pm2nNUgMYUiI6bDNpLKA132Lsw0t/jwpBOkI/VAIId7KDxrabSeHxtgexUd+Ovanl9DMfW8SMWV8= X-Received: by 2002:a50:d707:0:b0:57c:5fca:ab25 with SMTP id 4fb4d7f45d1cf-57d07e84bf2mr724934a12.25.1718776876913; Tue, 18 Jun 2024 23:01:16 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 19 Jun 2024 06:01:16 +0000 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287465 Archived-At: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > OK, I have a first cut at the doc done. > So, here's what I'm proposing, presented as a single diff. > Some commit messages still need to be improved (and I just noticed that > the files' copyright lines also need to be fixed), but other than that, > I think it's about ready. > > Comments? Objections? Thanks, LGTM. I have some comments and questions below. > diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi > index 6bf4cbe00df..5287a90bb71 100644 > --- a/doc/emacs/custom.texi > +++ b/doc/emacs/custom.texi > @@ -1550,6 +1550,41 @@ Directory Variables > do not visit a file directly but perform work within a directory, such > as Dired buffers (@pxref{Dired}). > > +@node EditorConfig support > +@subsubsection Per-Directory Variables via EditorConfig > +@cindex EditorConfig support > + > +The EditorConfig standard is an alternative to the @code{.dir-locals.el} > +files, which can control only a very small number of variables, but > +has the advantage of being editor-neutral. Those settings are stored in > +files named @code{.editorconfig}. > +If you want Emacs to obey those settings, you need to enable > +the @code{editorconfig-mode} minor mode. This is usually all that is > +needed: when the mode is activated, Emacs will look for @code{.editorcon= fig} > +files whenever a file is visited, just as it does for @code{.dir-locals.= el}. Is it ever dangerous to load settings from these files or is it always safe? Should that be documented somewhere, e.g.: In contrast to @code{.dir-locals.el}, it is always considered safe to load settings from @code{.editorconfig} files. (See @xref{...}) > +When both @code{.editorconfig} and @code{.dir-locals.el} files are > +encountered, the corresponding settings are combined, and in case there ^^^^^^^^^^^ a simpler word might suffice: "found" > +is overlap, the settings coming from the nearest file take precedence. I don't think I understand this: - Does "overlap" mean "conflict"? - What does "nearest" mean; which one is preferred? > +The @code{indent_size} setting of the EditorConfig standard does not > +correspond to a fixed variable in Emacs, but instead needs to set > +different variables depending on the major mode. Ideally all major > +modes should set the corresponding @code{editorconfig-indent-size-vars}, > +but if you use a major mode in which @code{indent_size} does not take > +effect because the major mode does not yet support it, you can customize > +the @code{editorconfig-indentation-alist} variable to tell Emacs which > +variables need to be set in that major mode. Does this suggest that our in-tree major modes should set that variable, IOW that we should spread the knowledge to those modes? That should also help encourage major mode authors elsewhere to do the same. Should this be documented also in (info "(elisp) Major Mode Conventions")? > +Similarly, there are several different ways to ``trim whitespace'' at ^^ ^^ > +the end of lines. When the EditorConfig @code{trim_trailing_whitespace} > +setting is used, by default @code{editorconfig-mode} simply calls > +@code{delete-trailing-whitespace} every time you save your file. > +If you prefer some other behavior, You can customize ^^^ lowercase > +@code{editorconfig-trim-whitespaces-mode} to the minor mode of > +your preference, such as @code{ws-butler-mode}. Why square quotes around "trim whitespace"? I think they can be removed. > @node Connection Variables > @subsection Per-Connection Local Variables > @cindex local variables, for all remote connections > diff --git a/etc/NEWS b/etc/NEWS > index b2fdbc4a88f..06742d24afe 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -1964,6 +1964,14 @@ The following new XML schemas are now supported: > =0C > * New Modes and Packages in Emacs 30.1 > > +** New package EditorConfig. > +This package provides support for the EditorConfig standard that > +is an editor-neutral way to provide directory local settings. Suggested: This package provides support for the EditorConfig standard, an editor-neutral way to provide directory local (project) settings. > +It is enabled via a new global minor mode 'editorconfig-mode' > +which makes Emacs obey the '.editorconfig' files. > +And the package also comes with a new major mode 'editorconfig-conf-mode= ' ^^^ > +to edit those configuration files. Suggest replacing "And the package also comes with a new major mode" with "There is also a new major mode". > new file mode 100644 > index 00000000000..2b4ddd4410f > --- /dev/null > +++ b/lisp/editorconfig-conf-mode.el > @@ -0,0 +1,95 @@ > +;;; editorconfig-conf-mode.el --- Major mode for editing .editorconfig f= iles -*- lexical-binding: t -*- > + > +;; Copyright (C) 2011-2024 EditorConfig Team > + > +;; Author: EditorConfig Team > + > +;; See > +;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributor= s > +;; or the CONTRIBUTORS file for the list of contributors. ^^^^^^^^^^^^^^^^^^^^^ Suggested: "the CONTRIBUTORS file in the linked git repository" > +(defsubst editorconfig-core-handle--string-trim (str) > + "Remove leading and trailing whitespaces from STR." > + (replace-regexp-in-string "[[:space:]]+\\'" > + "" > + (replace-regexp-in-string "\\`[[:space:]]+" > + "" > + str))) Could this be replaced by string-trim? Also, is this defsubst unused? > +(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 ena= ble > + ;; code conversion > + (insert-file-contents conf) > + (goto-char (point-min)) > + (let ((sections ()) > + (top-props nil) > + > + ;; nil when pattern not appeared yet, "" when pattern is emp= ty ("[]") > + (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 "\\([^=3D: \t]+\\)[ \t]*[=3D:][ \t]*\\(.*?\\)[ \= t]*$") > + (let ((key (downcase (match-string 1))) > + (value (match-string 2))) > + (when (and (< (length key) 51) > + (< (length value) 256)) > + (if pattern > + (when (< (length pattern) 4097) ;;FIXME: 4097? > + (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-pos= ition) > + (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 > diff --git a/lisp/editorconfig-core.el b/lisp/editorconfig-core.el > new file mode 100644 > index 00000000000..908d5db6f7e > --- /dev/null > +++ b/lisp/editorconfig-core.el > @@ -0,0 +1,156 @@ > +;;; editorconfig-core.el --- EditorConfig Core library in Emacs Lisp -*= - lexical-binding: t -*- Suggest scratching "in Emacs Lisp" as redundant > +(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) > + (package-get-version) > + (let* ((version > + (with-temp-buffer > + (require 'find-func) > + (declare-function find-library-name "find-func" (li= brary)) > + (insert-file-contents (find-library-name "editorcon= fig")) > + (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=3D version pkg-version))) > + (concat version "-" pkg-version) > + version))))) > + (when show-version > + (message "EditorConfig Emacs v%s" version-full)) > + version-full)) Can this function be removed and/or obsoleted? I would like us to discourage such functions in favor of using standard functions (e.g. `M-x list-packages' or `C-h p') to find out what version of a package is installed.