Giter Club home page Giter Club logo

trailingspaces's Introduction

Trailing Spaces

A Sublime Text plugin that allows you to…

highlight trailing spaces and delete them in a flash!


Synopsis

Sublime Text provides a way to automate deletion of trailing spaces upon file saving (more on this at the end of this file). Depending on your settings, it may be more handy to just highlight them and/or delete them by hand, at any time. This plugin provides just that, and a lot of options to fine-tune the way you want to decimate trailing spaces.

Installation

It is available through Sublime Package Control and this is the recommended way of installation (brings configuration instructions, automatic updates with changelogs…).

Alternative installation methods

From github

You can install from github if you want, although Package Control automates just that. Go to your Packages directory (find out where it is by running Preferences: Browse Packages from The Command Palette) and clone this repository:

git clone https://github.com/SublimeText/TrailingSpaces.git

Manually

Download the plugin as a zip. Copy the Trailing Spaces directory to its location (see prior section).

Usage

Deletion

The main feature you gain from using this plugin is that of deleting all trailing spaces in the currently edited document. In order to use this deletion feature, you may either:

  • click on "Edit / Trailing Spaces / Delete";
  • bind the deletion command to a keyboard shortcut:

To add a key binding, open "Preferences / Key Bindings - User" and add:

{ "keys": ["ctrl+shift+t"], "command": "delete_trailing_spaces" }

With this setting, pressing Ctrl + Shift + t will delete all trailing spaces at once in the current file! For OSX users, quoting wbond: "When porting a key binding across OSes, it is common for the ctrl key on Windows and Linux to be swapped out for super on OS X" (eg. use "super+shift+t" instead).

Beware: the binding from this example overrides the default ST's mapping for reopening last closed file. You can look at the default bindings in "Preferences / Key Bindings - Default".

Toggling highlighting

At any time, you can toggle highlighting on and off. You may either:

  • click on "Edit / Trailing Spaces / Highlight Regions"
  • bind the toggling command to a keyboard shortcut:
// I like "d", as in "detect" (overrides a default binding, though).
{ "keys": ["ctrl+shift+d"], "command": "toggle_trailing_spaces" }

Options

Several options are available to customize the plugin's behavior. Those settings are stored in a configuration file, as JSON. You must use a specific file: Go to "Preferences / Package Settings / Trailing Spaces / Settings" to add you custom settings.

A few of them are also accessible through the "Edit / Trailing Spaces" menu. Sometimes, editing a setting will require a fresh Sublime Text to be applied properly, so try relaunching ST before reporting an issue ;)

All settings are global (ie. applied to all opened documents).

Changing the highlighting color

Default: "invalid"

You may change the highlighting color, providing a color scope name such as "error", "comment"… just like that:

{ "highlight_color": "comment" }

The scope should be defined in your current theme file. Here is a dummy, fully-fledged example (feel free to cut irrelevant pieces for your settings) of such a custom color scope:

<dict>
  <key>name</key>
  <string>Invalid - Illegal</string>
  <key>scope</key>
  <string>invalid.illegal</string>
  <key>settings</key>
  <dict>
    <key>background</key>
    <string>#F93232</string>
    <key>fontStyle</key>
    <string></string>
    <key>foreground</key>
    <string>#F9F2CE</string>
  </dict>
</dict>

You would then use the value of "invalid.illegal".

Keeping trailing spaces invisible

You can make trailing spaces "invisible" yet still rely on the deletion command. To do that, set the highlight scope to an empty string:

{ "highlight_color": "" }

Beware: this is not the same as disabling the highlighting (see "On- Demand Matching" below). With this setting, the plugin still runs when opening a file, and in the background afterwards; you just won't see the trailing spaces (they are being highlighted with a "transparent" color).

Include Current Line

Default: true

Highlighting of trailing spaces in the currently edited line can be annoying: each time you are about to start a new word, the space you type is matched as a trailing spaces. Currently edited line can thus be ignored:

{ "include_current_line": false }

Even though the trailing spaces are not highlighted on this line, they are still internally matched and will be delete when firing the deletion command.

Include Empty Lines

Default: true

When firing the deletion command, empty lines are matched as trailing regions, and end up being deleted. You can specifically ignore them:

{ "include_empty_lines": false }

They will not be highlighted either.

Modified Lines Only

Default: false (reopen ST to update)

When firing the deletion command, trailing regions in the entire document are deleted. There are some use-cases when deleting trailing spaces only on lines you edited is smarter; for instance when commiting changes to some third-party source code.

At any time, you can change which area is covered when deleting trailing regions. You may either:

  • click on "Edit / Trailing Spaces / Modified Lines Only"
  • specify as a setting:
{ "modified_lines_only": true }

There is also a command to toggle this feature on and off. You may thus define a key binding:

{ "keys": ["pick+a+shortcut"], "command": "toggle_trailing_spaces_modified_lines_only" }

Trim On Save

Default: false

Setting this to true will ensure trailing spaces are deleted when you save your document. It abides by the other settings, such as Modified Lines Only.

{ "trim_on_save": true }

Save After Trim

Default: false

You may not want to always trim trailing spaces on save, but the other way around could prove useful. Setting this to true will automatically save your document after you fire the deletion command:

{ "save_after_trim": true }

It is obviously ignored if Trim On Save is on.

Live Matching vs On-demand Matching

Default: true (reopen ST to update)

By default, trailing regions are matched every time you edit the document, and when you open it.

This feature is entirely optional and you may set it off: firing the deletion command will cause the trailing spaces to be deleted as expected even though they were not matched prior to your request. If you are afraid of the plugin to cause slowness (for instance, you already installed several heavy plugins), you can disable live matching:

{ "enabled": false }

In this case, for no trailing regions are matched until you request them to be deleted, no highlighting occurs—it is in fact disabled, regardless of your "scope" setting. If you want to check the trailing spaces regions, you can toggle highlighting on and off. In this case, it may come in handy to define a binding for the toggling command. When "On-demand Matching" is on and some trailing spaces are highlighted, added ones will obviously not be. Toggling highlight off and on will refresh them.

Ignore Scope

Default: ["text.find-in-files", "source.build_output", "source.diff", "text.html.markdown"]

With this option you can ignore lines being highlighted based on the scope of their trailing region.

If at least one scope in the configured list matches a scope in the trailing region of the line, it won't be highlighted.

By default, the scope under the mouse cursor is shown by pressing Option+Command+P (OS X) or Ctrl+Alt+Shift+P (Windows, Linux)

// Trailing spaces for Find Results, Build output, Diff and Markdown are ignored
{ "scope_ignore": ["text.find-in-files", "source.build_output", "source.diff", "text.html.markdown"] }

For power-users only!

Disabled for large files

The plugin is disabled altogether for large files, for it may cause slowness. The default threshold is around 1 million of characters. This is configurable (in "File Settings - User") and the unit is number of chars:

{ "file_max_size": 1000}

The matching pattern

Default: [ \t]+

Trailing spaces are line-ending regions containing at least one simple space, tabs, or both. This pattern should be all you ever need, but if you do want to abide by another definition to cover edge-cases, go ahead:

// *danger* will match newline chars and many other folks
"regexp": "[\\s]+"

About Sublime Text's built-in features

Trailing Spaces is designed to be a drop-in replacement of the limited Trim Whitespace On Save built-in feature. ST is indeed able to delete trailing spaces upon saving files, and maybe that's all you need!

In order to enable this behavior, edit "Preferences / Settings" to add the following:

{ "trim_trailing_white_space_on_save": true }

As Trailing Spaces bypasses this setting, you will have to uninstall it to benefit from this setting.

Made a little less obvious in the documentation are settings to showcase whitespaces (not only trailing ones!):

{ "draw_white_space": "all" }

and to ensure a newline is kept at end of file upon saving:

{ "ensure_newline_at_eof_on_save": true }

The former will display all whitespaces in your files. There is another value of "selection" which display whitespaces under (you got it) your current text selection.

trailingspaces's People

Contributors

abh avatar apuchkov avatar bentruyman avatar betaorbust avatar brockspratlen avatar chikamichi avatar darkred avatar dnicolson avatar eyenseo avatar facelessuser avatar fichtefoll avatar ihabunek avatar jamie-pate avatar jbrooksuk avatar ka8725 avatar kyldvs avatar macbem avatar mheinzler avatar morrisoncole avatar nicholasbuse avatar q3xq3r avatar rchl avatar rcopera avatar sgtpooki avatar simjega avatar smanolloff avatar ulfsauer0815 avatar xiaochuanyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trailingspaces's Issues

Modified Lines Only

As proposed in #8, replicate RubyMine's feature (http://www.jetbrains.com/ruby/webhelp/editor.html): upon deletion, proceed with respect to a setting describing which lines should be affected (All | Modified Lines | None).

In RubyMine, it occurs at saving only ("Strip trailing spaces on Save"), so their default value is of None. It is not relevant for this plugin, though, so we are only concerned about the choice between All and Modified Lines.

This feature could prove very useful in conjunction with automated trimming on save, so it may make the case for providing a setting "trim_on_save" with a default value of False.

Setting a different color scope

I realize you're busy. Hopefully this is an easy fix.

I'm using the Soda theme, and I'm using Espresso Soda.tmTheme. In that file, there is the following defintion:

    <dict>
        <key>name</key>
        <string>Invalid - Illegal</string>
        <key>scope</key>
        <string>invalid.illegal</string>
        <key>settings</key>
        <dict>
            <key>background</key>
            <string>#F93232</string>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#F9F2CE</string>
        </dict>
    </dict>

In my user preferences, I have set:

{   
    ...
    "trailing_spaces_highlight_color": "invalid.illegal",
    ...
}

I'm getting an odd color for trailing spaces that doesn't change, regardless of whether I set the above setting, and regardless of what I set it to. The color I get is like the inverse of Monokai: a pink-bordered black box.

It's pretty jarring with this color scheme, so if I'm doing something wrong, I'd like to fix it.

Wrong lines being highlighted

Either I'm misunderstanding how this works or it's doing something odd with Python. In this screenshot, there is NO trailing space on the first line, but it's being highlighted. There ARE trailing spaces on the second line, but it's not being highlighted.

Can you clarify please? Thanks.

screen shot 2013-12-04 at 2 18 17 pm

Latest commit breaks ST2

I'm getting:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 205, in on_activated
  File "./sublime_plugin.py", line 154, in run_timed_function
  File "./sublime_plugin.py", line 204, in <lambda>
  File "./trailing_spaces.py", line 97, in on_activated
  File "./trailing_spaces.py", line 59, in highlight_trailing_spaces
AttributeError: 'NoneType' object has no attribute 'get'

It's getting picked up and updated automatically by Package Control, not sure if that is intended. Might need to create another branch.

don't consider the first column in a diff

In a unified diff, the first column is always filled: either with a + to mean "added", a - to mean "removed", or a space to mean "nothing changed". If a line is blank, this space will be there anyway. It would be great for TrailingSpaces to not highlight these, so that I can see legitimate trailing whitespace added by a diff without those distractions.

simply does not work?

I install this plugin. (I am on Windows). I choose the Edit / Trailing Spaces / Delete command.

Nothing seems to happen. Trailing spaces are not in fact deleted. Although I don't see any visible error message.

Is there anything I can easily do to provide more debugging info? (I do not have experience developing ST plugins).

Is this plugin still in fact supported/maintained by anyone?

ST3: UnicodeDecodeError on non-UTF-8 files

When editing old code written in CP1252, I get this in the console:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 303, in on_activated
    callback.on_activated(v)
  File "trailing_spaces in /Users/serge/Library/Application Support/Sublime Text 3/Installed Packages/TrailingSpaces.sublime-package", line 395, in on_activated
  File "trailing_spaces in /Users/serge/Library/Application Support/Sublime Text 3/Installed Packages/TrailingSpaces.sublime-package", line 416, in freeze_last_version
  File "X/codecs.py", line 679, in read
  File "X/codecs.py", line 482, in read
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 607: invalid continuation byte

0xe9 is latin-1 for "�é" (and is also the same in unicode, not as UTF-8). ST3 properly detects the CP1252 encoding.

Broken in ST2

Traceback (most recent call last):
  File "./sublime_plugin.py", line 200, in on_selection_modified
  File "./sublime_plugin.py", line 154, in run_timed_function
  File "./sublime_plugin.py", line 199, in <lambda>
  File "./trailing_spaces.py", line 392, in on_selection_modified
  File "./trailing_spaces.py", line 123, in match_trailing_spaces
  File "./trailing_spaces.py", line 90, in find_trailing_spaces
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Writing file /Users/carl/Code/spec/controllers/categories_controller_spec.rb with encoding UTF-8

Option Request: Ignore indentation

Could we please have a configurable option to ignore unused indentation? Meaning any white space between newlines with no other text. I like to keep lines between code blocks at the same indentation level as the lines above and below it, and the plugin really hates that.

Example:
Screen Shot 2012-12-11 at 11 22 01 AM

on_pre_save fails for new files

For new files being saved, freeze_last_version called from on_pre_save tries to open a file that is about to be created (but it's not yet there). So the open() fails with FileNotFoundError.

Modified Lines Only broken on Windows

The feature breaks on Win 7:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 531, in run_
    return self.run(edit)
  File "C:\Users\jd\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 426, in run
  File "C:\Users\jd\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 330, in delete_trailing_regions
  File "C:\Users\jd\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 282, in find_regions_to_delete
  File "C:\Users\jd\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 257, in get_modified_lines
  File "C:\Users\jd\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 232, in modified_lines_as_numbers
  File "X/difflib.py", line 913, in compare
  File "X/difflib.py", line 567, in get_opcodes
  File "X/difflib.py", line 484, in get_matching_blocks
TypeError: object of type 'NoneType' has no len()

Need to wrap codecs.open in try/catch in freeze_last_version

I find my console littered with things like this:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 303, in on_activated
    callback.on_activated(v)
  File "trailing_spaces in C:\Users\Bill\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package", line 395, in on_activated
  File "trailing_spaces in C:\Users\Bill\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package", line 416, in freeze_last_version
  File "X/codecs.py", line 884, in open
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Bill\\AppData\\Local\\Temp\\$$_49F1\\Default (Windows).sublime-mousemap'

which seems to happen whenever I delete/rename a file that is open in ST3. Not fatal or anything, but it's a distraction in the console.

Command to force to delete all trailing spaces

Now I set "trailing_spaces_modified_lines_only" to true in the configuration, this feature is really useful to me. But sometimes I really need to delete all trailing spaces in the whole file, not only modified lines, but after I use command to delete trailing spaces, some spaces are not removed. So I guess the problem is "trailing_spaces_modified_lines_only". Is there any way that I can force to delete trailing spaces in the whole file? Thanks.

Wrong old descriptor file when using MLO

While investigating #39, I realized that when switching tabs/opening a new file/whatever changes the view, the old file descriptor (coming from the cached on_disk value) used for comparing versions is messed up: it describes the first opened file, not the currently active view. This results in all trailing spaces being deleted, defeating the very purpose of the MLO setting.

The on_disk cache should be overwritten when hitting the on_activated hook, so that the proper, active file is considered. This may be an issue when switching back and forth between files though (we don't want to erase a valid old/on_disk descriptor. Maintaining an array of descriptors under the on_load hook may then be smarter. Plus, populating the cache if no matching descriptor for the current, active view is found at diff time.

Can't work well now.

It worked in ST2 before, but can't work(I mean it can't highlight trailing spaces) now after it upgraded in the last time.

Ignore lines that only contain whitespace

Hello,

Is it possible to ignore lines that only contain whitespaces?

For example, if I'm inside an indented context, and press Enter 5 times to make some room, I get a lot of highlighted spaces.
I made a few new lines to clear some of the noise and now I have too much colour haha.

Plugin keeps file open

The plugin keeps the current file open, at least if the file has more than 1000 lines. This keeps the file from beeing changed on Windows platform e.g. by git checkout branch.

I think changing the method freeze_last_version to

        with codecs.open(file_name, "r", "utf-8") as f:
            on_disk = f.read().splitlines()

would solve the issue (I'm no python guy).

Another question: The method on_activated is defined twice. Is this by purpose?

Can't turn highlighting off. Plus I hate pink. = Rather annoying.

No matter what I do, I just can't "toggle" trailing space highlighting off. So now every document I work on is peppered with bright pink - even in places where I'm happy to let sleeping whitespace lie..

A few things I've tried:

  • "Toggling" trailing spaces off
  • Toggling trailing spaces on, then off, then on, then off again
  • Closing the current file and opening a different one
  • Closing that different file then opening the original (yes - pink still there)
  • Closing an entire project then reopening it
  • Closing an entire project then toggling trailing spaces off, then reopening the project
  • Closing an entire project then toggling trailing spaces on, then off, then reopening the project
  • Restarting Sublime (yes - still pink)

This is where it gets good:

  • Disabling the plugin completely (pink still there)
  • Closing all files and projects, enabling the plugin, then disabling it, then opening a file (still there)
  • Removing the plugin completely, and visualising flushing it down a toilet (still there)
  • Punching my computer screen (oh yes - PINK STILL THERE)

So a little perplexed as you can imagine. Not to mention a little pissed.

Anything I can do to remove this god-forsaken pink from my sights? Or am I doomed forever to have every Sublime document I ever work on lightly sprinkled with bright pink splodges?

TrailingSpaces package does not work in ST2

I have ST2. Option "auto_upgrade" set to "true" in my Package Control settings. Today I've noticed that TrailingSpaces package does not work properly: neither highlight, nor remove trailing spaces.
I tried to remove/install package -- no changes.

Sublime Text v. 2.0.2
TrailingSpaces v.2013.07.25.08.58.10;github.com/SublimeText/TrailingSpaces

But in ST3 this package works fine.

Disabling removal of whitespace on the current empty line on save

Hey, apologies if this issue has already come up in the past but I really can't find a solution using the available settings.

I often find myself opening a new block (say a function) and going to a new line where there's only really the indentation. I will then switch the window to my browser and, since I have automatic saving enabled, it'll save and trim whitespace, including the indentation on the current line which is needed for me to be able to write the code inside the function later.
I tried "trailing_spaces_include_empty_lines": false but at that point it'll ignore all empty lines, which is not what I want because I'd like empty lines with stray indentation to be removed correctly.

Is there a way to make it ignore the current line if it's empty but only because I have my cursor on it, and delete all other empty lines?

Handle empty settings file

ST2 dislikes empty settings files. It requires extra-care and currently the code is filled with redundant default values (as constants) to ensure the settings globals are in proper order during execution… ST3 will ignore empty files at load_settings time to handle this.

As for ST2 is concerned, maybe this could be improved by checking whether the settings file is empty and, if so, getting rid of it before late.

Don't highlight spaces while typing on a new line

I love TrailingSpaces, but when I am writing new lines it always highlights the space as you type them (because logically, in that moment it's a trailing space). One fix would be to ignore current line.

Broken in ST3

Noticed this while installing the plugin on ST3:

Traceback (most recent call last):
File "C:\MJ\Programs\Windows\Sublime Text 3\sublime_plugin.py", line 286, in on_selection_modified
callback.on_selection_modified(v)
File "C:\MJ\Programs\Windows\Sublime Text 3\Data\Packages\TrailingSpaces\trailing_spaces.py", line 392, in on_selection_modified
match_trailing_spaces(view)
File "C:\MJ\Programs\Windows\Sublime Text 3\Data\Packages\TrailingSpaces\trailing_spaces.py", line 123, in match_trailing_spaces
(matched, highlightable) = find_trailing_spaces(view)
File "C:\MJ\Programs\Windows\Sublime Text 3\Data\Packages\TrailingSpaces\trailing_spaces.py", line 90, in find_trailing_spaces
regexp = ts_settings.get("trailing_spaces_regexp") + "$"
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Simple fix would be to change line 90 to

regexp = ts_settings.get("trailing_spaces_regexp", "") + "$"

Simply not working on windows

Hi there,

Unfortunatelly it is not working on my windows 7 box.
I get no highlight and despite having confugured it to trim on save, it just don't do it.
Tried trimming manually, and also don't do it.

Latest update makes it not working

Probably similar as issue #46

After the latest update, it simply doesn't work.

Tried "Deleting Trailing Spaces", the message reads "No trailing spaces to delete!". No highlights either. Tried restart ST2 several times, no effects.

It was working yesterday...

No longer working

Hi,

I updated to Sublime Text 2 Beta, Build 2181, and now on save no longer removes spaces. I tried to add the key binding rule you have set up, and doesn't work. Though i still see highlighting and if i use cmd + shift + P i can search for trailing and remove spaces that way. Anyone else having issues with on save no longer removing?

Thanks,
David

automatically clean up lines that I type, but not others

If I'm editing a file, I don't want to add new trailing whitespace, but I also don't want to be submitting massive diffs that clean up all the whitespace in a big file while I'm making an unrelated change.

So when I type "return return ", I want to automatically clean up the whitespace that's left behind, but I don't want to use the "nuclear option" of "delete trailing spaces", since that's going to affect lots of lines I didn't write.

A good start on this would be for "delete trailing spaces" to only work on selected lines, if there's an active selection.

Sanitize trailing_spaces_include_current_line

Fix { "trailing_spaces_include_current_line": false } so that the hilighting of current line is toggled off only when you start editing that line. Or even better, only when start editing at the end of line.

This way, when manually deleting trailing spaces, the hilighting would not disappear just when you're about to delete it (because of entering that line).

When fixed, make { "trailing_spaces_include_current_line": false } the default.

Btw. instead of providing "a lot of options to fine-tune the way you want to decimate trailing spaces", I'd prefer to not have options, just sane default ones :)

Weird interaction with highlighting?

This package occasionally seem to break the behaviour of the text selection feature of ST2 (i.e. click and drag over text).

Occasionally, when attempting to select text, the beginning of the selection always jumps to the very bottom of the document and updates very jaggedly.

This usually seems to occur when the bottom line of the document is in view. Scrolling up and back down seems to temporarily fix the issue, though it eventually reoccurs. Deactivating this package seems to have removed the issue.

In case the issue is a conflict with other packages, I also have the following installed:

  • SublimeLinter
  • Emmet
  • Git
  • Package Control
  • NodeJS

ignore lines that are just whitespace

hi,

I'd like an option to ignore lines that are just whitespace. Those are often indented to the level of the preceding block and I see no issue with that (and half our codebase is like that) so it's distracting and destructive for your otherwise wonderful plugin to be reacting to those.

I'd have tried to code this up and submitted a pull request if it weren't 7am right now :)

thanks for considering and thanks for a very useful plugin!

~allixsenos

UnicodeDecodeError when document gains focus

If a document is opened with the encoding "Western (Windows 1252)" that contains invalid UTF-8 an error appears in the console:

Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 303, in on_activated
callback.on_activated(v)
File "/Users/dave/Library/Application Support/Sublime Text 3/Installed Packages/TrailingSpaces.sublime-package/trailing_spaces.py", line 395, in on_activated
self.freeze_last_version(view)
File "/Users/dave/Library/Application Support/Sublime Text 3/Installed Packages/TrailingSpaces.sublime-package/trailing_spaces.py", line 416, in freeze_last_version
on_disk = codecs.open(file_name, "r", "utf-8").read().splitlines()
File "X/codecs.py", line 679, in read
File "X/codecs.py", line 482, in read
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa9 in position 1789: invalid start byte

Perhaps a conditional to get the encoding of the document could help, as with this example (line 36):

https://github.com/demon386/SmartMarkdown/blob/master/pandoc_render.py

It doesn't appear to be possible to get the codec name from Sublime Text (only the long name) to match up with this list:

http://docs.python.org/release/2.5.2/lib/standard-encodings.html

Settings Being Overwritten?

I'm not sure if this is an issue with TrailingSpaces or ST3, but it's only happened with this bundle so I'm posting here.

For some reason, my settings keep being overwritten. I edit my user-specific package settings to look like this:

{
    "trailing_spaces_highlight_color": "trailingspaces.invalid"
}

Then a few days later I notice that it's not highlighting anymore, so I open the file and see this:

{
    "trailing_spaces_highlight_color": ""
}

This has happened several times now, and only for TrailingSpaces. Any idea what could be up?

'trailing_spaces_highlight_color' is lost

Looks like plugin doesn't respect 'trailing_spaces_highlight_color' setting in 'File Settings - User' anymore.
Had to overwrite in 'trailing_spaces.sublime-settings' to make it work.
Keep up the good work!

I love this! It would be amazing to be able to remove non-trailing whitespace as well

This is a very useful plugin! I would love to also be able to remove whitespace that is not trailing and doesn't follow my indentation style (tabs vs. spaces).

Sometimes when copying code into a file the indenting ends up getting copied, e.g. if I use 4 spaces as tab size and use tabs instead of spaces for indentation.

.some-element {
    border: 1px solid #000; // my styles
      width: 200px; // copied styles
}

Note the extra whitespace yet it isn't trailing. Would it be possible for your plugin to remove the non-trailing whitespace as well and match my indentation style?

Thanks for your help!

example

Error when copy & delete some text

When i'm using this extension occurs the following error:

If i copy some text, and after that i delete some other text, the deleted text will replace the clipboard text... this is annoying!

Mu sublime text version is: 2.0.2 build 2221

Highlight whitespace characters other than space and tab as well

TrailingSpaces currently only highlights trailing space and tab characters. Other whitespace characters might not be common, but appear from time to time (like an accidentally typed Alt-Space on OSX (it's Shift-Space on Windows, I guess)).

Changing the regular expression from '[ \t]+$' to '\s+$' should do it.

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.