Giter VIP home page Giter VIP logo

ws-butler's Introduction

Build Status

ws-butler -- an unobtrusive way to trim spaces from end of line

  • Only lines touched get trimmed. If the white space at end of buffer is changed, then blank lines at the end of buffer are truncated respecting require-final-newline.

  • Trimming only happens when saving.

What does unobtrusive mean?

The user is not made explicitly aware when trimming happens. You keep working and the butler takes care of whitespace for you.

This means if point is at a location that was trimmed, point is not moved, but the data on disk has been cleaned up (revert the buffer to confirm).

Not moving point because of space deletion.

By default, ws-butler preserves "virtual spaces" in front of point if necessary. The file on disk is cleaned up however.

This can be disabled with ws-butler-keep-whitespace-before-point.

Trimming only specific lines.

There might be lines you don't want to get trimmed, e.g. spaces in multiline strings. The behavior can be customized through ws-butler-trim-predicate. This variable should hold a function that expects 2 arguments (region beginning and end) and should return true only for regions that one wants to get trimmed. As an example

(setq ws-butler-trim-predicate
      (lambda (beg end)
        (not (eq 'font-lock-string-face
                 (get-text-property end 'face)))))

Installation

Debian 9 or later or Ubuntu 16.10 or later

apt-get install elpa-ws-butler

History

  1. I started by trimming all spaces at EOL in source code in a "write-file-hook" when I started programming. It seemed like a great idea.

  2. Then I got a job working on a code base where no one else trimmed spaces, so my commits became super noisy. I wanted to stop being the "white space" police, so switched to ws-trim.

    • ws-trim works in a post-command-hook and trims white space while you edit.
    • This was too eager for me. For example, I would stop and scroll away to look at some code, and when I get back to continue, my indentation is gone.
    • It caused some problems with other customizations which also rely on post-command-hook.
  3. I started experimenting with using highlight-changes-mode to trim only lines I touch on save.

  4. Now, the dependency on highlight-changes-mode has been removed and we handle change changing through text properties ourselves.

This is the result

ws-butler's People

Contributors

chris-martin avatar darwinawardwinner avatar ilohmar avatar lewang avatar spwhitton avatar xificurc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.