def test_remove_trailing_spaces():
    buffer = gtk.TextBuffer()
    buffer.set_text(u"   \nword слово   \t  \n   \t \n\n   word  слово      """)

    remove_trailing_spaces(buffer)
    text = buffer.get_text(*buffer.get_bounds()).decode('utf-8')
    assert text == u"\nword слово\n\n\n   word  слово"
Beispiel #2
0
    def save(self):
        if not self.saveable:
            self.message("This file was opened with error and can't be saved")
            return

        if self.uri:
            if self.before_file_save.emit():
                return

            if self.prefs['remove-trailing-space']:
                from snaked.core.processors import remove_trailing_spaces
                remove_trailing_spaces(self.buffer)

            try:
                save_file(self.uri, self.utext, self.encoding)
                if not self.buffer.get_modified():
                    self.message("%s saved" % self.uri)
                self.buffer.set_modified(False)
                try:
                    self.file_mtime = os.path.getmtime(self.uri)
                except(OSError):
                    self.file_mtime = None #the file does not exist any more
                self.file_saved.emit()
            except Exception, e:
                self.message(str(e), 5000)
Beispiel #3
0
    def save(self):
        if not self.buffer.saveable:
            self.message("This file was opened with error and can't be saved", 'warn')
            return

        if self.uri:
            if self.before_file_save.emit():
                return

            if self.buffer.config['remove-trailing-space']:
                from snaked.core.processors import remove_trailing_spaces
                remove_trailing_spaces(self.buffer)

            # TODO quick hack to ignore file changes by snaked itself
            try:
                save_file(self.uri, self.utext, self.encoding)
                self.buffer.monitor.saved_by_snaked = True
                if not self.buffer.get_modified():
                    self.message("%s saved" % self.uri, 'done')
                self.buffer.set_modified(False)
                self.file_saved.emit()
            except Exception, e:
                self.message(str(e), 'error', 5000)