Default to ANSI sometimes

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
IanOfYork
Posts: 118
Joined: Sat Nov 04, 2017 11:54 am
Location: York, England

Default to ANSI sometimes

Post by IanOfYork »

I have a lot of text files. They all have a .TXT suffix.

Most of the time I want to treat them as UTF-8.
However, there are some sets of files that are intended to be ANSI.
Opening these as UTF-8 will mangle a few characters.

Is there any way to configure Textpad to treat specific directories as ANSI and others as UTF-8?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I don't believe there is a way to specify the encoding by directory. But you can specify the encoding by filename extension:
in
Configure | Preferences | Document Classes | <Class>
for
Default encoding:
select ANSI or UTF-8.

You can override this when opening an individual file by specifying the Encoding.
IanOfYork
Posts: 118
Joined: Sat Nov 04, 2017 11:54 am
Location: York, England

Post by IanOfYork »

I have a lot of text files. They all have a .TXT suffix.
So far, Textpad only seems aware of the file suffix.

It would be good (for me) if there was an option for a regex against the full path/filename.suffix, but I suspect that nobody else would find this to be of any use.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

I have no experience with this, but as much as I have read, .editorconfig could be a solution (but don't ask me what exactly has to be put into that file ...)
IanOfYork
Posts: 118
Joined: Sat Nov 04, 2017 11:54 am
Location: York, England

Post by IanOfYork »

C:\Users\---\AppData\Roaming\Helios\TextPad\8\ConfigState.xml
contains entries for document classes in this format ...

Code: Select all

<class name="Text" type="2"> 
  <value name="Members" type="collection"> 
    <element>*.</element>
    <element>*.TXT</element>
    <element>*.INI</element>
    ...
So, the test currently seems to be restricted to the filename.suffix and ignores the path.
This matches what we see in Preferences / Document Classes

I will log an enhancement request to widen the tests.
IanOfYork
Posts: 118
Joined: Sat Nov 04, 2017 11:54 am
Location: York, England

Suggested

Post by IanOfYork »

User avatar
bbadmin
Site Admin
Posts: 878
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post by bbadmin »

If you want all the text files in a subfolder to be opened as ANSI, when the default is UTF-8, you can use .editorconfig files, as suggested by MudGuard.

Create a file named .editorconfig in the particular subfolder with the following contents:

Code: Select all

[*.txt]
charset = latin1
Enable handling of such files on Configure/Preferences/Editor settings.

Note that TextPad will then recursively search for .editorconfig files in every parent folder, accumulating overrides as it goes. This can slow things down with remote files, so it's best to create one starting with "root = true" in the topmost folder you want to override settings for.

Note also that if after doing this you open the file from the recently used list on the File menu, it will still open with the character encoding it was last opened with.

The settings which can be overridden are documented here:

https://editorconfig-specification.readthedocs.io/

I hope this helps.
User avatar
ineuw
Posts: 191
Joined: Sun Mar 18, 2007 3:23 pm

Post by ineuw »

I dealt with such issues by creating a different document class with its own extension. But then, I don't share files just store them in the cloud.
TextPad 8.16.0 64bit in English and TextPad 9.1.0 64bit in French, on two separate Windows installations
Post Reply