diff --git a/.emacs.d/lisp/code/editorconfig-c.el b/.emacs.d/lisp/code/editorconfig-c.el index d7f1635..1046f65 100644 --- a/.emacs.d/lisp/code/editorconfig-c.el +++ b/.emacs.d/lisp/code/editorconfig-c.el @@ -27,4 +27,28 @@ Debug warning is suppressed if SUPPRESS is non-nil." (kotct/editorconfig-check-for-core kotct/editorconfig-suppress-core-not-found-warning) +(defvar kotct/warn-on-editorconfig-with-no-props + t + "If not false-y, warn when editing a file with no editorconfig properties +applying, indicating that the user is stuck with Emacs' default style for the +active buffer.") + +(defun kotct/check-editorconfig-props (props) + "Warn the user if a file is being edited with EditorConfig active but no +properties were applied. + +The argument PROPS is a property hash table provided by the EditorConfig +package, and contains key-value pairs corresponding to the user's configured +style for the current buffer. If this hash table is empty, no properties were +applied to the buffer, so the user is at the whims of Emacs' default style for +the active mode, which may not be desirable." + + (if kotct/warn-on-editorconfig-with-no-props + (let ((fn (buffer-file-name)) + (bn (buffer-name))) + (if (and fn (= 0 (hash-table-count props))) + (message (format "EditorConfig mode is active for buffer %s, but no properties were applied." bn)))))) + +(add-hook #'editorconfig-after-apply-functions #'kotct/check-editorconfig-props) + (provide 'editorconfig-c) diff --git a/.emacs.d/lisp/code/indentation.el b/.emacs.d/lisp/code/indentation.el index d4defdb..a58eaeb 100644 --- a/.emacs.d/lisp/code/indentation.el +++ b/.emacs.d/lisp/code/indentation.el @@ -1,44 +1,3 @@ -;; set the default tab width to 4 chars -;; this is the reference variable for the tab width -(setf global-tab-width 4) - -;; define automated tab-setting system -(defvar kotct/tab-variable-setters - '((global-tab-width . setf)) - "An alist of symbols representing variables and the method -used to set them to the tab width -(almost always either setf or setq-default).") - -(defmacro kotct/setf-tab (var) - "Set the variable VAR to the tab width and keep it updated -if the tab width changes." - `(progn - (setf ,var global-tab-width) - (setf kotct/tab-variable-setters (cons '(,var . setf) kotct/tab-variable-setters)))) - -(defmacro kotct/setq-default-tab (var) - "Set default value of the variable VAR to the tab width -and keep it updated if the tab width changes." - `(progn - (setq-default ,var global-tab-width) - (setf kotct/tab-variable-setters (cons '(,var . setq-default) kotct/tab-variable-setters)))) - -(defmacro kotct/set-tab-width (width) - "Set `global-tab-width' and all other associated tab width -variables in `kotct/tab-variable-setters' to WIDTH." - (cons 'progn - (mapcar (lambda (pair) (list (cdr pair) (car pair) width)) - kotct/tab-variable-setters))) - -(kotct/setq-default-tab tab-width) -(kotct/setf-tab smie-indent-basic) - -;; Set the base indent variable. -(kotct/setf-tab standard-indent) - -;; by default, don't use tabs -(setq-default indent-tabs-mode nil) - ;; when you hit DEL on a tab, delete the whole tab, don't convert to spaces (setf backward-delete-char-untabify-method nil) diff --git a/.emacs.d/lisp/code/languages/c.el b/.emacs.d/lisp/code/languages/c.el index 9ca9bd7..4737c8b 100644 --- a/.emacs.d/lisp/code/languages/c.el +++ b/.emacs.d/lisp/code/languages/c.el @@ -3,10 +3,4 @@ ;; set style to linux (setf c-default-style "linux") -;; use tab-width for indentation -(kotct/setf-tab c-basic-offset) - -;; use smart tabs -(smart-tabs-insinuate 'c) - (provide 'c) diff --git a/.emacs.d/lisp/code/languages/fish.el b/.emacs.d/lisp/code/languages/fish.el index 5c6c742..bd8187f 100644 --- a/.emacs.d/lisp/code/languages/fish.el +++ b/.emacs.d/lisp/code/languages/fish.el @@ -1,11 +1,3 @@ (require 'fish-mode) -(smart-tabs-add-language-support fish fish-mode-hook - ((fish-indent-line . standard-indent) - (fish-indent-region . standard-indent))) - -(smart-tabs-insinuate 'fish) - -(add-hook 'fish-mode-hook (lambda () (setf indent-tabs-mode t))) - (provide 'fish) diff --git a/.emacs.d/lisp/code/languages/java.el b/.emacs.d/lisp/code/languages/java.el index d4d330e..edf8446 100644 --- a/.emacs.d/lisp/code/languages/java.el +++ b/.emacs.d/lisp/code/languages/java.el @@ -1,5 +1,3 @@ ;; TODO: implement IDE-like java editing -(smart-tabs-insinuate 'java) - (provide 'java) diff --git a/.emacs.d/lisp/code/languages/ruby.el b/.emacs.d/lisp/code/languages/ruby.el index 760be20..e0eff61 100644 --- a/.emacs.d/lisp/code/languages/ruby.el +++ b/.emacs.d/lisp/code/languages/ruby.el @@ -1,20 +1,5 @@ (require 'indentation) -;; Set ruby-indent-level to global-tab-width -(kotct/setq-default-tab ruby-indent-level) - -;; Add Smart Tabs language support for Ruby using the -;; `smart-tabs-add-language-support' macro. -(smart-tabs-add-language-support ruby ruby-mode-hook - ((ruby-indent-line . ruby-indent-level) - (ruby-indent-level . ruby-indent-level))) - -;; Apply Ruby language support to Smart Tabs. -(smart-tabs-insinuate 'ruby) - -;; Use tabs mode in Ruby by default. -(setf ruby-indent-tabs-mode t) - ;; Don't use SMIE because SMIE sucks. (setf ruby-use-smie nil) diff --git a/.emacs.d/lisp/code/languages/rust.el b/.emacs.d/lisp/code/languages/rust.el index d2df13b..0c6d820 100644 --- a/.emacs.d/lisp/code/languages/rust.el +++ b/.emacs.d/lisp/code/languages/rust.el @@ -1,18 +1,5 @@ (require 'indentation) -;; Set `rust-indent-offset' to the `global-tab-width' value. -(kotct/setq-default-tab rust-indent-offset) - -;; Add language support for Rust. -(smart-tabs-add-language-support rust rust-mode-hook - ((rust-mode-indent-line . rust-indent-offset))) - -;; Use `indent-tabs-mode' in `rust-mode' -(add-hook 'rust-mode-hook (lambda () (setf indent-tabs-mode t))) - -;; Turn on Rust support in Smart Tabs. -(smart-tabs-insinuate 'rust) - ;; Don't indent `where' clauses in Rust. (setf rust-indent-where-clause nil) diff --git a/.emacs.d/lisp/code/languages/sh.el b/.emacs.d/lisp/code/languages/sh.el index 250e03d..b48eae3 100644 --- a/.emacs.d/lisp/code/languages/sh.el +++ b/.emacs.d/lisp/code/languages/sh.el @@ -1,12 +1,5 @@ (require 'indentation) -;; Synchronize `sh-basic-offset' and `sh-indentation' to the global tab size -(kotct/setf-tab sh-basic-offset) -(kotct/setf-tab sh-indentation) - -;; Always use indent-tabs-mode in sh-mode -(add-hook 'sh-mode-hook (lambda () (setf indent-tabs-mode t))) - ;; Indent case labels at the same level as the case statement (setf sh-indent-for-case-label 0) diff --git a/.emacs.d/lisp/code/languages/web-c.el b/.emacs.d/lisp/code/languages/web-c.el index c9ff96a..9d8960f 100644 --- a/.emacs.d/lisp/code/languages/web-c.el +++ b/.emacs.d/lisp/code/languages/web-c.el @@ -19,6 +19,4 @@ (setf web-mode-enable-control-block-indentation nil) (setf web-mode-script-padding 0) -(add-hook 'web-mode-hook (lambda () (setf indent-tabs-mode t))) - (provide 'web-c) diff --git a/.emacs.d/test/lisp/code/editorconfig-c-test.el b/.emacs.d/test/lisp/code/editorconfig-c-test.el new file mode 100644 index 0000000..537d697 --- /dev/null +++ b/.emacs.d/test/lisp/code/editorconfig-c-test.el @@ -0,0 +1,31 @@ +(kotct/load-corresponding) + +(describe "kotct/check-editorconfig-props" + (before-each + (spy-on #'message)) + (describe "on a file with no corresponding editorconfig props" + (describe "when kotct/warn-on-editorconfig-with-no-props is truthy" + (it "prints a warning" + (let* ((kotct/warn-on-editorconfig-with-no-props t) + (temp-file-name (make-temp-file "tests")) + (temp-file-buffer (create-file-buffer temp-file-name))) + (progn + (with-current-buffer temp-file-buffer + (setf buffer-read-only t) + (set-visited-file-name temp-file-name) + (expect (buffer-file-name) :to-equal temp-file-name) + (expect #'message :to-have-been-called) + (expect #'message :to-have-been-called-with + (format "EditorConfig mode is active for buffer %s, but no properties were applied." (buffer-name)))))))) + + (describe "when kotct/warn-on-editorconfig-with-no-props is not truthy" + (it "doesn't print a warning" + (let* ((kotct/warn-on-editorconfig-with-no-props nil) + (temp-file-name (make-temp-file "tests")) + (temp-file-buffer (create-file-buffer temp-file-name))) + (progn + (with-current-buffer temp-file-buffer + (setf buffer-read-only t) + (set-visited-file-name temp-file-name) + (expect (buffer-file-name) :to-equal temp-file-name) + (expect #'message :not :to-have-been-called)))))))) diff --git a/.emacs.d/test/lisp/code/languages/sh-test.el b/.emacs.d/test/lisp/code/languages/sh-test.el index 5f1e489..fde3ed7 100644 --- a/.emacs.d/test/lisp/code/languages/sh-test.el +++ b/.emacs.d/test/lisp/code/languages/sh-test.el @@ -3,10 +3,6 @@ (kotct/load-corresponding) (describe "sh config" - (it "adds a tab variable setter for `sh-basic-offset'" - (expect (assoc 'sh-basic-offset kotct/tab-variable-setters) :to-be-truthy)) - (it "adds a tab variable setter for `sh-indentation'" - (expect (assoc 'sh-indentation kotct/tab-variable-setters) :to-be-truthy)) (it "sets the indentation for case labels to 0" (expect sh-indent-for-case-label :to-be 0)) (it "sets the indentation for case alts to be one level"