AutoHotkey files need to be UTF-8 encoded with BOM only if the *.ahk file does not contain only ASCII characters as far as I know.
Python script files can be with DOS/Windows or Unix line endings as far as I know.
It is not possible to configure in UEStudio or UltraEdit which line ending type and which character encoding without or with BOM is used by default by UEStudio/UltraEdit depending on the file extension. A feature request must be sent by email to technical support of UltraEdit, Inc. as described on the
technical support page.
There could be done following:
- Open Advanced - Settings or Configuration - File handling - Encoding and select for Default encoding (for new files and file open when auto-detect fails) either ANSI or UTF-8 as needed most for new files. I suggest UTF-8 as default encoding as Python and AutoHotkey files should be both UTF-8 encoded and these two file types are most often created and edited in UEStudio.
- In Configuration click next on DOS/Unix/Mac handling and select for Default file type for new files either DOS or Unix as needed most for new files. I suggest DOS as being better in general on Windows.
- In Configuration click next on Save and check or uncheck Write UTF-8 BOM header to all UTF-8 files when saved and Write UTF-8 BOM on new files created within this program (if above is not set) as needed most for already UTF-8 encoded files and newly created UTF-8 encoded files. I suggest unchecking both.
- Then close the Configuration.
Next must be created a macro with a name like
OnSave which is saved into a macro file like
LoadSave.mac which is best stored in a subdirectory
Macros in the directory
%APPDATA%\IDMComp\UEStudio (or
%APPDATA%\IDMComp\UltraEdit for UltraEdit). This macro file can contain multiple macros but contains best only one macro which is executed once by UltraEdit on every file save (and perhaps a second macro executed once by UltraEdit on every file open).
The macro code for the macro
OnSave could be:
Code: Select all
IfExtIs "py"
DosToUnix
ExitMacro
EndIf
IfExtIs "ahk"
ToggleBookmark
HexOn
Find Up "EF BB BF"
IfNotFound
Top
HexInsert 3
"EF BB BF"
EndIf
HexOff
GotoBookMark 1
ToggleBookmark
ExitMacro
EndIf
The macro property
Show cancel dialog for this macro should not be checked and the macro property
Continue if search string not found must be checked for this macro. The third macro property
Disable screen refresh during macro playback can be checked or unchecked, best would be unchecked.
This macro must be configured to be executed on every file save. In ribbon mode click on last ribbon tab
Advanced in third group
Macro on the down arrow right to the last item
Configure and next on last pop-up menu item
Macro settings. In toolbar/menu with contemporary menus click in menu
Advanced in submenu
Configure on the last menu item
Macro settings. In toolbar/menu with traditional menus click in menu
Macro on the menu item
Set macro for file load/save. The configuration for execution of the macro
OnSave in the file
LoadSave.mac once on file save should be self-explaining.
There is one thing which must be considered on saving a new file or an already existing, named file with
Save as: The macro is executed
before the file name is entered in the
Save as dialog window. The file extension is for that reason unknown on macro execution on first save of a new file and is not yet changed if an existing file is saved with a new file extension using the
Save as command. There must be in these two use cases edited the just saved new file or just saved existing file with new file extension a second time and then saved again.
The macro run on every file save could be also coded like this:
Code: Select all
IfNameIs ""
ToggleBookmark
Top
Find "string always present in Python scripts"
IfFound
DosToUnix
Else
Find "string always present in AutoHotkey files"
IfFound
HexOn
Find Up "EF BB BF"
IfNotFound
Top
HexInsert 3
"EF BB BF"
EndIf
HexOff
EndIf
EndIf
GotoBookMark 1
ToggleBookmark
EndIf
This macro runs only on save of a new, unnamed file one or two
Find to find out if the new file is a
Python script or a
AutoHotkey file and makes the necessary changes different to the default settings before the file is saved with selecting the directory and entering the file name. I do not know if there are strings which can be used to identify a new file as
Python script or as
AutoHotkey file or as a different file (nothing done).
Another solution could be writing an UltraEdit/UEStudio script which is used always for saving a new file like with hotkey
F12. The UltraEdit/UEStudio script prompts the user for the file name. Then the script evaluates the file extension and converts the file to the appropriate character encoding without or with BOM and also to appropriate line ending type before it next saves the new file with the user entered file name in the current directory. The disadvantage of this solution is that the directory cannot be selected by the user on using the script for
Save as of a new file.