Skip to content

Instantly share code, notes, and snippets.

@basecode
Created December 22, 2011 11:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save basecode/1509946 to your computer and use it in GitHub Desktop.
Save basecode/1509946 to your computer and use it in GitHub Desktop.
'no-break space' detection plugin for Sublime Text 2
# encoding: utf-8
import sublime, sublime_plugin
class DetectSpecialCharacters(sublime_plugin.EventListener):
def on_load(self, view):
sublime.status_message("detect_special_characters is active")
def on_modified(self, view):
# find no-break space
special_characters = view.find_all(u"\u00A0")
if len(special_characters) > 0:
sublime.error_message("ohhh noose! detected a NO-BREAK SPACE (U+00A0)")
@relikd
Copy link

relikd commented Sep 27, 2018

Updated script with inline notification.

# encoding: utf-8

import sublime
import sublime_plugin


class DetectSpecialCharacters(sublime_plugin.EventListener):

    def on_load(self, view):
        sublime.status_message("detect_nonbreaking_space is active")

    def on_modified(self, view):
        html = "<div style='color:black;background-color:#E00;padding:0px 2px'>NBSP</div>"
        view.erase_phantoms('nbsp-warn')
        # find no-break space
        for r in view.find_all(u"\u00A0"):
            view.add_phantom('nbsp-warn', r, html, sublime.LAYOUT_INLINE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment