From 8d936f2d0bc8934acc1fb3263012939274b02e48 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 8 May 2018 19:59:08 +0200 Subject: [PATCH] Move editorconfig out of core into tools/editorconfig --- core/core-editor.el | 56 -------------------------- core/packages.el | 1 - init.example.el | 1 + modules/tools/editorconfig/README.org | 18 +++++++++ modules/tools/editorconfig/config.el | 51 +++++++++++++++++++++++ modules/tools/editorconfig/packages.el | 4 ++ 6 files changed, 74 insertions(+), 57 deletions(-) create mode 100644 modules/tools/editorconfig/README.org create mode 100644 modules/tools/editorconfig/config.el create mode 100644 modules/tools/editorconfig/packages.el diff --git a/core/core-editor.el b/core/core-editor.el index 957ae51f8..fcd88a23e 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -117,62 +117,6 @@ fundamental-mode) for performance sake." ;; Core Plugins ;; -;; Handles whitespace (tabs/spaces) settings externally. This way projects can -;; specify their own formatting rules. -(def-package! editorconfig - :hook (doom-init . editorconfig-mode) - :config - ;; Register missing indent variables - (setq editorconfig-indentation-alist - (append '((mips-mode mips-tab-width) - (haxor-mode haxor-tab-width) - (nasm-mode nasm-basic-offset)) - editorconfig-indentation-alist)) - - ;; editorconfig cannot procure the correct settings for extension-less files. - ;; Executable scripts with a shebang line, for example. So why not use Emacs' - ;; major mode to drop editorconfig a hint? This is accomplished by temporarily - ;; appending an extension to `buffer-file-name' when we talk to editorconfig. - (defvar doom-editorconfig-mode-alist - '((sh-mode . "sh") - (python-mode . "py") - (ruby-mode . "rb") - (perl-mode . "pl") - (php-mode . "php")) - "An alist mapping major modes to extensions. Used by -`doom*editorconfig-smart-detection' to give editorconfig filetype hints.") - - (defun doom*editorconfig-smart-detection (orig-fn &rest args) - "Retrieve the properties for the current file. If it doesn't have an -extension, try to guess one." - (let ((buffer-file-name - (if (and (not (bound-and-true-p org-src-mode)) - (file-name-extension buffer-file-name)) - buffer-file-name - (format "%s%s" buffer-file-name - (if-let* ((ext (cdr (assq major-mode doom-editorconfig-mode-alist)))) - (concat "." ext) - ""))))) - (apply orig-fn args))) - (advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection) - - ;; Editorconfig makes indentation too rigid in Lisp modes, so tell - ;; editorconfig to ignore indentation. I prefer dynamic indentation support - ;; built into Emacs. - (dolist (mode '(emacs-lisp-mode lisp-mode)) - (map-delete editorconfig-indentation-alist mode)) - - (defvar whitespace-style) - (defun doom|editorconfig-whitespace-mode-maybe (&rest _) - "Show whitespace-mode when file uses TABS (ew)." - (when indent-tabs-mode - (let ((whitespace-style '(face tabs tab-mark trailing-lines tail))) - (whitespace-mode +1)))) - (add-hook 'editorconfig-custom-hooks #'doom|editorconfig-whitespace-mode-maybe)) - -(def-package! editorconfig-conf-mode - :mode "\\.?editorconfig$") - ;; Auto-close delimiters and blocks as you type (def-package! smartparens :config diff --git a/core/packages.el b/core/packages.el index fec04dde7..d40910824 100644 --- a/core/packages.el +++ b/core/packages.el @@ -25,7 +25,6 @@ (package! ace-window) (package! avy) (package! command-log-mode) -(package! editorconfig) (package! expand-region) (package! helpful) (package! pcre2el) diff --git a/init.example.el b/init.example.el index 3c759cee0..e57336bc1 100644 --- a/init.example.el +++ b/init.example.el @@ -43,6 +43,7 @@ :tools dired ; making dired pretty [functional] + editorconfig ; let someone else argue about tabs vs spaces ein ; tame Jupyter notebooks with emacs electric-indent ; smarter, keyword-based electric-indent eshell ; a consistent, cross-platform shell (WIP) diff --git a/modules/tools/editorconfig/README.org b/modules/tools/editorconfig/README.org new file mode 100644 index 000000000..f7a7d37a5 --- /dev/null +++ b/modules/tools/editorconfig/README.org @@ -0,0 +1,18 @@ +#+TITLE: :tools editorconfig + +Editorconfig integration for Doom. + +* Table of Contents :TOC: +- [[Module Flags][Module Flags]] +- [[Prerequisites][Prerequisites]] +- [[Configuration][Configuration]] + +* Module Flags +This module provides no flags. + +* Prerequisites +~editorconfig~ is an optional requirement of this package. The elisp-only +implementation may be sufficient, but has fewer features. + +* Configuration + diff --git a/modules/tools/editorconfig/config.el b/modules/tools/editorconfig/config.el new file mode 100644 index 000000000..bbe4cbaf6 --- /dev/null +++ b/modules/tools/editorconfig/config.el @@ -0,0 +1,51 @@ +;;; tools/editorconfig/config.el -*- lexical-binding: t; -*- + +;; Handles whitespace (tabs/spaces) settings externally. This way projects can +;; specify their own formatting rules. +(def-package! editorconfig + :hook (doom-init . editorconfig-mode) + :config + ;; Register missing indent variables + (setq editorconfig-indentation-alist + (append '((mips-mode mips-tab-width) + (haxor-mode haxor-tab-width) + (nasm-mode nasm-basic-offset)) + editorconfig-indentation-alist)) + + ;; editorconfig cannot procure the correct settings for extension-less files. + ;; Executable scripts with a shebang line, for example. So why not use Emacs' + ;; major mode to drop editorconfig a hint? This is accomplished by temporarily + ;; appending an extension to `buffer-file-name' when we talk to editorconfig. + (defvar doom-editorconfig-mode-alist + '((sh-mode . "sh") + (python-mode . "py") + (ruby-mode . "rb") + (perl-mode . "pl") + (php-mode . "php")) + "An alist mapping major modes to extensions. Used by +`doom*editorconfig-smart-detection' to give editorconfig filetype hints.") + + (defun doom*editorconfig-smart-detection (orig-fn &rest args) + "Retrieve the properties for the current file. If it doesn't have an +extension, try to guess one." + (let ((buffer-file-name + (if (and (not (bound-and-true-p org-src-mode)) + (file-name-extension buffer-file-name)) + buffer-file-name + (format "%s%s" buffer-file-name + (if-let* ((ext (cdr (assq major-mode doom-editorconfig-mode-alist)))) + (concat "." ext) + ""))))) + (apply orig-fn args))) + (advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection) + + ;; Editorconfig makes indentation too rigid in Lisp modes, so tell + ;; editorconfig to ignore indentation there. I prefer dynamic indentation + ;; support built into Emacs. + (dolist (mode '(emacs-lisp-mode lisp-mode)) + (map-delete editorconfig-indentation-alist mode))) + + +(def-package! editorconfig-conf-mode + :mode "\\.?editorconfig$") + diff --git a/modules/tools/editorconfig/packages.el b/modules/tools/editorconfig/packages.el new file mode 100644 index 000000000..716c3b55e --- /dev/null +++ b/modules/tools/editorconfig/packages.el @@ -0,0 +1,4 @@ +;; -*- no-byte-compile: t; -*- +;;; tools/editorconfig/packages.el + +(package! editorconfig)