Move editorconfig out of core into tools/editorconfig

This commit is contained in:
Henrik Lissner 2018-05-08 19:59:08 +02:00
parent 99ca62c106
commit 8d936f2d0b
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395
6 changed files with 74 additions and 57 deletions

View File

@ -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

View File

@ -25,7 +25,6 @@
(package! ace-window)
(package! avy)
(package! command-log-mode)
(package! editorconfig)
(package! expand-region)
(package! helpful)
(package! pcre2el)

View File

@ -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)

View File

@ -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

View File

@ -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$")

View File

@ -0,0 +1,4 @@
;; -*- no-byte-compile: t; -*-
;;; tools/editorconfig/packages.el
(package! editorconfig)