Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
I'd like to indent my Python scripts with four spaces, and my HTML/XML documents with two spaces. Is there a way of specifying per-document-type indents?
There should be. I knew I forgot something. Franz suggested this.
As long as I am at it, are there any other per document type preferences that should be set?
(I can't think of any at the moment.)
For me applies:
these two variables could be get from the settings
self.addchar = "\t".expandtabs(2)
self.tabwidth = 2
self.addchar = "\t".expandtabs(GetTabWidth())
self.tabwidth = GetTabWidth()
or simply replace self.tabwidth with GetTabWidth()
Most of the things in the Prefences Document page could be set as per-type. For instance, word wrap might make sense for HTML, but not Python; the Python comment string doesn't make much sense in HTML or C++; etc.
Word wrap as well works.
Comment string too.
(This will be fun ;P).
Ok. So here is what I have so far:
Line Ending Type
Context Sensitive AutoIndent (At the moment, only for python)
At the moment, file types will be:
Python, C/C++, HTML, Plain Text.
Although I should probably add pyrex support at some point.
I am thinking of implementing this as a dictionary,
so that you'd have
The only thing I am a bit muddled about is letting people set these globally.
> The only thing I am a bit muddled about is letting people set these globally.
Hmm, tricky. One option is not to have a global setting at all, and add a "Apply these preferences to all languages" button, similar to the existing "Apply Text Property To All Styles" button. After all, I only need to set up my document preferences once, so any pain will hopefully be soon forgotten.
If someone wants to be really clever, they can edit the preferences file directly. :-)
> I am thinking of implementing this as a dictionary,
Why not make prefs aware of the current file type, so you don't have to pass it in every time? For per-type preferences, you could use a dictionary of file types, each of which stores the per-type dictionary. Then you could do something like
def __getattr__(self, pref):
if pref in self.__dict__:
and call it like
prefs = drPreferences(type=...)
tabwidth = prefs.tabwidth
Less typing, looks nicer.
The problem is prefs are a member of DrFrame, and there can be multiple documents, each with their own file type.
So the filetype has to be part of the Document.
I could add functions like:
Ah, so it is.
If you added methods like GetTabWidth(), you need one for every preference, which is getting a little unwieldy, and clutters up the source browser.
What about in DrFrame, something like:
def getPreference(self, preference, language=None):
where perLanguagePrefs is a dictionary keyed on language containing dictionaries keyed on preference names. (Or use some other data structure: you know the internals better than I do.)
Now you can use
for language-specific preferences, and
for global preferences.
Although you can also access prefs as a dictionary,