From a49fda9c7930df7ecaa813cc5c6bdfac9308332d Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 15 Oct 2020 10:30:02 -0700 Subject: [PATCH] Use ws-butler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At work I have to work with a lot of files that other people work on as well. Other people don’t usually have their editor set up to remove all trailing whitespace, and we’re not allowed to make a change that includes a lot of extra whitespace changes[1]. So I end up having to revert a lot of whitespace changes just before submitting. And if I then have to make more changes, for example because something was pointed out in a code review, I have to do it again. ‘ws-butler’ promises that it will still prevent me from submitting extraneous whitespace, but will not touch lines that I haven’t changed, so that would prevent me from having to revert them all the time. [1]: This is good, having a lot of whitespace changes can distract from or even completely hide the actual change you’re trying to make. --- oni-core.el | 13 +++++-------- test/integration/oni-core.bats | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/oni-core.el b/oni-core.el index 512dc4d..620a337 100644 --- a/oni-core.el +++ b/oni-core.el @@ -4,8 +4,8 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.1015.100916 -;; Package-Requires: (oni-data-dir expand-region multiple-cursors embrace gcmh diminish) +;; Version: 2020.1015.102640 +;; Package-Requires: (oni-data-dir expand-region multiple-cursors embrace gcmh diminish ws-butler) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ (require 'gcmh) (require 'oni-data-dir) (require 'recentf) +(require 'ws-butler) (defconst oni-core--auto-save-directory (oni-data-dir-locate "auto-save-files/") "Directory where auto-saves go.") @@ -40,11 +41,6 @@ (defvar oni-core--recentf-idle-timer nil "Internal variable keeping track of a timer started for ‘recentf-save-list’.") -(defun oni-core--destroy-trailing-whitespace () - "Delete trailing whitespace everywhere, except in Markdown buffers." - (if (not (eq major-mode 'markdown-mode)) - (delete-trailing-whitespace))) - (defun oni-core--switch-newline-keys () "Switch the ‘C-j’ and ‘RET’ keys in the local buffer." (if electric-indent-mode @@ -131,7 +127,6 @@ (setq-default truncate-lines t) (setq-default fill-column 80) -(add-hook 'before-save-hook #'oni-core--destroy-trailing-whitespace) (add-hook 'before-save-hook 'time-stamp) (add-hook 'electric-indent-local-mode-hook #'oni-core--switch-newline-keys) (add-hook 'minibuffer-setup-hook 'electric-pair-local-mode) @@ -155,11 +150,13 @@ (run-with-idle-timer 10 t #'oni-core-recentf-save-list-silently))) (diminish 'gcmh-mode) +(diminish 'ws-butler-mode) (electric-indent-mode -1) (winner-mode) (recentf-mode) (gcmh-mode) +(ws-butler-global-mode) (add-to-list 'display-buffer-alist `(,(rx string-start diff --git a/test/integration/oni-core.bats b/test/integration/oni-core.bats index adf6a4f..373d3ea 100755 --- a/test/integration/oni-core.bats +++ b/test/integration/oni-core.bats @@ -35,3 +35,21 @@ [[ "$output" == *"t" ]] } + +@test "Starting Emacs diminishes ws-butler-global-mode" { + run emacs -batch -l package -f package-initialize -l subr-x \ + -eval "(prin1 (string-empty-p (car (alist-get 'ws-butler-mode minor-mode-alist))))" + + echo "$output" + + [[ "$output" == *"t" ]] +} + +@test "Starting Emacs turns on ws-butler-mode" { + run emacs -batch -l package -f package-initialize \ + -eval "(prin1 (bound-and-true-p ws-butler-mode))" + + echo "$output" + + [[ "$output" == *"t" ]] +}