From 789b8db7a4bff9c7e66803688af6b5ee3b43ffea Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Mon, 3 Sep 2018 20:02:32 +0900 Subject: [PATCH] Implement editorconfig-auto-apply-mode --- .editorconfig | 2 ++ emacs.el | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.editorconfig b/.editorconfig index bcf7644..fda987a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,8 @@ trim_trailing_whitespace = true insert_final_newline = true max_line_length = 80 +a=bhoehoe + [*.js] indent_size = 2 diff --git a/emacs.el b/emacs.el index 701525d..ae837b3 100644 --- a/emacs.el +++ b/emacs.el @@ -1600,6 +1600,36 @@ This mode is a simplified version of `adoc-mode'." (buffer-substring-no-properties (point-min) (point-max)))) )) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; editorconfig-auto-apply + +(define-minor-mode editorconfig-auto-apply-mode + "When saving .editorconfig file update buffer configs." + :global t + :lighter "" + (if editorconfig-auto-apply-mode + (add-hook 'after-save-hook + 'editorconfig-auto-apply-mode--when-save) + (remove-hook 'after-save-hook + 'editorconfig-auto-apply-mode--when-save))) + +(defun editorconfig-auto-apply-mode--when-save () + "Function run when editorconfig" + (when (eq major-mode + 'editorconfig-conf-mode) + (let ((dir (file-name-directory buffer-file-name))) + (cl-dolist (buf (buffer-list)) + (when (and (buffer-file-name buf) + (file-in-directory-p (buffer-file-name buf) + dir)) + (with-current-buffer buf + (editorconfig-mode-apply))))))) + +(editorconfig-auto-apply-mode 1) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defun my-file-head (filename &optional n) "Return list of first N lines of file FILENAME." ;; Work with japanese text?