diff --git a/src/calibre/gui2/tweak_book/editor/smart/__init__.py b/src/calibre/gui2/tweak_book/editor/smart/__init__.py index 3ef356517a..828998d119 100644 --- a/src/calibre/gui2/tweak_book/editor/smart/__init__.py +++ b/src/calibre/gui2/tweak_book/editor/smart/__init__.py @@ -8,6 +8,8 @@ __copyright__ = '2014, Kovid Goyal ' class NullSmarts(object): + override_tab_stop_width = None + def __init__(self, editor): pass diff --git a/src/calibre/gui2/tweak_book/editor/smart/python.py b/src/calibre/gui2/tweak_book/editor/smart/python.py index f785484644..5e285960e8 100644 --- a/src/calibre/gui2/tweak_book/editor/smart/python.py +++ b/src/calibre/gui2/tweak_book/editor/smart/python.py @@ -35,6 +35,8 @@ def get_leading_whitespace_on_line(editor, previous=False): class Smarts(NullSmarts): + override_tab_stop_width = 4 + def handle_key_press(self, ev, editor): key = ev.key() diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e5d2517cb9..a8b8040e19 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -173,7 +173,7 @@ class TextEdit(PlainTextEdit): self.apply_theme(theme) w = self.fontMetrics() self.space_width = w.width(' ') - tw = 4 if self.syntax == 'python' else prefs['editor_tab_stop_width'] + tw = self.smarts.override_tab_stop_width if self.smarts.override_tab_stop_width is not None else prefs['editor_tab_stop_width'] self.setTabStopWidth(tw * self.space_width) if dictionaries_changed: self.highlighter.rehighlight() @@ -220,12 +220,12 @@ class TextEdit(PlainTextEdit): sclass = get_smarts(syntax) if sclass is not None: self.smarts = sclass(self) + if self.smarts.override_tab_stop_width is not None: + self.setTabStopWidth(self.smarts.override_tab_stop_width * self.space_width) self.setPlainText(unicodedata.normalize('NFC', unicode(text))) if process_template and QPlainTextEdit.find(self, '%CURSOR%'): c = self.textCursor() c.insertText('') - if syntax == 'python': - self.setTabStopWidth(4 * self.space_width) def change_document_name(self, newname): self.highlighter.doc_name = newname